android 中未显示 OnItemclickListner Toast 消息
OnItemclickListner Toast message not showing in android
您好,在下面的代码中动态实现了自动完成 textview 并保存了响应 locally.Now 如果我搜索字母 'a' 那么它会显示并设置自动完成文本 textview.setext 正在工作很好,当我被选中时,文本想要获取 Id
Onitemclick Toast 消息未显示。
谁能帮我看看我错在哪里
private void fetchProductnameJSON(){
autoproduct_name.setHint(Html.fromHtml ( "Item Name"+""));
handler.postDelayed(new Runnable() {
@Override
public void run() {
// Write code for your refresh logic
sessionId = getActivity().getIntent().getStringExtra("sessionId");
String operation = "syncModuleRecords";
String module = "Products";
String syncToken = "";
String mode = "public";
final GetNoticeDataService service = RetrofitInstance.getRetrofitInstance().create(GetNoticeDataService.class);
/** Call the method with parameter in the interface to get the notice data*/
Call<SyncModule> call = service.GetSyncModuleList(operation, sessionId, module, syncToken, mode);
/**Log the URL called*/
Log.i("URL Called", call.request().url() + "");
call.enqueue(new Callback<SyncModule>() {
@Override
public void onResponse(Call<SyncModule> call, Response<SyncModule> response) {
Log.e("response", new Gson().toJson(response.body()));
if (response.isSuccessful()) {
Log.e("response", new Gson().toJson(response.body()));
SyncModule syncModule = response.body();
Gson g = new Gson();
String jsonAllProducts = g.toJson(syncModule);
tinydb.putString("jsonAllProducts",jsonAllProducts);
workingOnResponseProduct(syncModule);
}
}
@Override
public void onFailure(Call<SyncModule> call, Throwable t) {
}
// progressDialog.dismiss();
});
}
}, 0);
return ;
}
private void workingOnResponseProduct(SyncModule syncModule) {
autoproduct_name.setHint(Html.fromHtml ( "Item Name"+""));
String success = syncModule.getSuccess();
if (success.equals("true")) {
SyncResults results = syncModule.getResult();
Sync sync = results.getSync();
ArrayList<SyncUpdated> syncUpdateds = sync.getUpdated();
for (SyncUpdated syncUpdated : syncUpdateds) {
String unitprice="";
product_id = syncUpdated.getId();
ArrayList<SyncBlocks> syncBlocks = syncUpdated.getBlocks();
for (SyncBlocks syncBlocks1 : syncBlocks) {
String label = syncBlocks1.getLabel();
//Basic Information
if (label.equals("Product Details")) {
ArrayList<SynFields> synFields = syncBlocks1.getFields();
for (SynFields synFields1 : synFields) {
String name = synFields1.getName();
values = synFields1.getValue();
if (name.equals("productname")) {
productname = String.valueOf(values);
product_name.add(productname);
Log.d("products",String.valueOf(product_name.size()));
RecordsProducts records = new RecordsProducts(product_id,productname);
recordsListProduct.add(records);
}
}
}
//pricing information
else if (label.equals("Pricing Information")) {
ArrayList<SynFields> synFields = syncBlocks1.getFields();
for (SynFields synFields1 : synFields) {
String name = synFields1.getName();
values = synFields1.getValue();
if (name.equals("unit_price")) {
unitprice = String.valueOf(values);
Log.d("unitprice",unitprice);
//
}
}
}
}
}
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(),android.R.layout.simple_list_item_1, product_name);
autoproduct_name.setAdapter(adapter);
autoproduct_name.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if(position+1 > 0) {
RecordsProducts recordsProducts=recordsListProduct.get(position);
String product_id=recordsProducts.getId();
Log.d("productid",product_id);
String productnames=recordsProducts.getProductname();
autoproduct_name.setText(productnames);
Toast.makeText(getContext(),"selected"+product_id,Toast.LENGTH_LONG).show();
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
TableRow tbrow0 = new TableRow(getContext());
Resources resource = getContext().getResources();
tbrow0.setLayoutParams(getLayoutParams());
tbrow0.addView(getTextView(0, "Product Name", Color.WHITE, Typeface.NORMAL, resource.getColor(R.color.tabs1)));
tbrow0.addView(getTextView(0, "Quantity", Color.WHITE, Typeface.NORMAL,resource.getColor(R.color.tabs1)));
tbrow0.addView(getTextView(0, "Unit Price", Color.WHITE, Typeface.NORMAL, resource.getColor(R.color.tabs1)));
tbrow0.addView(getTextView(0, "Total", Color.WHITE, Typeface.NORMAL, resource.getColor(R.color.tabs1)));
stk.addView(tbrow0,getLayoutParams());
//String[] namesList = p.split(",");
//String[] priceList = listprices.split(",");
}
这是这个答案的解决方案
autoproduct_name.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(position+1 > 0) {
RecordsProducts recordsProducts=recordsListProduct.get(position);
String product_id=recordsProducts.getId();
Log.d("productid",product_id);
String productnames=recordsProducts.getProductname();
autoproduct_name.setText(productnames);
Toast.makeText(getContext(),"selected"+product_id,Toast.LENGTH_LONG).show();
}
}
});
您好,在下面的代码中动态实现了自动完成 textview 并保存了响应 locally.Now 如果我搜索字母 'a' 那么它会显示并设置自动完成文本 textview.setext 正在工作很好,当我被选中时,文本想要获取 Id
Onitemclick Toast 消息未显示。
谁能帮我看看我错在哪里
private void fetchProductnameJSON(){
autoproduct_name.setHint(Html.fromHtml ( "Item Name"+""));
handler.postDelayed(new Runnable() {
@Override
public void run() {
// Write code for your refresh logic
sessionId = getActivity().getIntent().getStringExtra("sessionId");
String operation = "syncModuleRecords";
String module = "Products";
String syncToken = "";
String mode = "public";
final GetNoticeDataService service = RetrofitInstance.getRetrofitInstance().create(GetNoticeDataService.class);
/** Call the method with parameter in the interface to get the notice data*/
Call<SyncModule> call = service.GetSyncModuleList(operation, sessionId, module, syncToken, mode);
/**Log the URL called*/
Log.i("URL Called", call.request().url() + "");
call.enqueue(new Callback<SyncModule>() {
@Override
public void onResponse(Call<SyncModule> call, Response<SyncModule> response) {
Log.e("response", new Gson().toJson(response.body()));
if (response.isSuccessful()) {
Log.e("response", new Gson().toJson(response.body()));
SyncModule syncModule = response.body();
Gson g = new Gson();
String jsonAllProducts = g.toJson(syncModule);
tinydb.putString("jsonAllProducts",jsonAllProducts);
workingOnResponseProduct(syncModule);
}
}
@Override
public void onFailure(Call<SyncModule> call, Throwable t) {
}
// progressDialog.dismiss();
});
}
}, 0);
return ;
}
private void workingOnResponseProduct(SyncModule syncModule) {
autoproduct_name.setHint(Html.fromHtml ( "Item Name"+""));
String success = syncModule.getSuccess();
if (success.equals("true")) {
SyncResults results = syncModule.getResult();
Sync sync = results.getSync();
ArrayList<SyncUpdated> syncUpdateds = sync.getUpdated();
for (SyncUpdated syncUpdated : syncUpdateds) {
String unitprice="";
product_id = syncUpdated.getId();
ArrayList<SyncBlocks> syncBlocks = syncUpdated.getBlocks();
for (SyncBlocks syncBlocks1 : syncBlocks) {
String label = syncBlocks1.getLabel();
//Basic Information
if (label.equals("Product Details")) {
ArrayList<SynFields> synFields = syncBlocks1.getFields();
for (SynFields synFields1 : synFields) {
String name = synFields1.getName();
values = synFields1.getValue();
if (name.equals("productname")) {
productname = String.valueOf(values);
product_name.add(productname);
Log.d("products",String.valueOf(product_name.size()));
RecordsProducts records = new RecordsProducts(product_id,productname);
recordsListProduct.add(records);
}
}
}
//pricing information
else if (label.equals("Pricing Information")) {
ArrayList<SynFields> synFields = syncBlocks1.getFields();
for (SynFields synFields1 : synFields) {
String name = synFields1.getName();
values = synFields1.getValue();
if (name.equals("unit_price")) {
unitprice = String.valueOf(values);
Log.d("unitprice",unitprice);
//
}
}
}
}
}
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(),android.R.layout.simple_list_item_1, product_name);
autoproduct_name.setAdapter(adapter);
autoproduct_name.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if(position+1 > 0) {
RecordsProducts recordsProducts=recordsListProduct.get(position);
String product_id=recordsProducts.getId();
Log.d("productid",product_id);
String productnames=recordsProducts.getProductname();
autoproduct_name.setText(productnames);
Toast.makeText(getContext(),"selected"+product_id,Toast.LENGTH_LONG).show();
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
TableRow tbrow0 = new TableRow(getContext());
Resources resource = getContext().getResources();
tbrow0.setLayoutParams(getLayoutParams());
tbrow0.addView(getTextView(0, "Product Name", Color.WHITE, Typeface.NORMAL, resource.getColor(R.color.tabs1)));
tbrow0.addView(getTextView(0, "Quantity", Color.WHITE, Typeface.NORMAL,resource.getColor(R.color.tabs1)));
tbrow0.addView(getTextView(0, "Unit Price", Color.WHITE, Typeface.NORMAL, resource.getColor(R.color.tabs1)));
tbrow0.addView(getTextView(0, "Total", Color.WHITE, Typeface.NORMAL, resource.getColor(R.color.tabs1)));
stk.addView(tbrow0,getLayoutParams());
//String[] namesList = p.split(",");
//String[] priceList = listprices.split(",");
}
这是这个答案的解决方案
autoproduct_name.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(position+1 > 0) {
RecordsProducts recordsProducts=recordsListProduct.get(position);
String product_id=recordsProducts.getId();
Log.d("productid",product_id);
String productnames=recordsProducts.getProductname();
autoproduct_name.setText(productnames);
Toast.makeText(getContext(),"selected"+product_id,Toast.LENGTH_LONG).show();
}
}
});