我对 a 有问题ArrayList
,所以我想检查ArrayList
它并将其与 from 的值进行比较,TextView
并显示 aToast
的值TextView
是否已经存在。
这是我已经尝试过的一些代码:
代码 1
TextView namamenu=(TextView)findViewById(R.id.nama_menu2);
EditText jumlahmenu=(EditText)findViewById(R.id.txtJumlahMenu);
MenuInputClass sr = new MenuInputClass();
String hehe = namamenu.getText().toString();
String hihi = jumlahmenu.getText().toString();
sr.setNama_menu(hehe);
sr.setJumlah_menu(hihi);
//results is the arraylist
if(results.contains(hehe)) {
Toast.makeText(Appetizer_Activity.this, "already exist"+hehe, Toast.LENGTH_LONG).show();
}
代码 2:
if(results.contains(sr)) {
Toast.makeText(Appetizer_Activity.this, "already exist"+hehe, Toast.LENGTH_LONG).show();
}
我的 PemesananMenuClass : 公共类 PemesananMenuClass 扩展应用程序 {
private static String nama_menu;
private String harga_menu;
private String keterangan_menu;
private String gambar;
public void setNama_menu(String nama_menu) {
PemesananMenuClass.nama_menu=nama_menu;
}
public String getNama_menu() {
return (nama_menu);
}
actually there are some other artibute
我的 ListPemesananActivity 类:
public class ListPemesanan_Activity extends Activity {
Button submit_list_pemesanan,submit_reservasi_nomeja;
TextView cobacoba;
ArrayList<String> list = new ArrayList<String>();
ArrayAdapter<String> adapter;
//public static ArrayList<MenuInputClass> searchResults = GetSearchResults();
public static ListView list_pemesanan;
protected static ListView lv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_pemesanan_menu);
// adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, list);
// lv = (ListView) findViewById(R.id.list);
submit_list_pemesanan=(Button)findViewById(R.id.btn_submit_list_pemesanan);
submit_reservasi_nomeja=(Button)findViewById(R.id.btn_reservasi_meja);
list_pemesanan=(ListView)findViewById(R.id.list);
//final TextView tnamamenu = (TextView)findViewById(R.id.txtNamaMasuk);
//EditText tnomeja = (EditText)findViewById(R.id.txtNoMeja);
//final TextView tjumlahmenu = (TextView)findViewById(R.id.txtJumlahMasuk);
OnClickListener listener = new OnClickListener() {
@Override
public void onClick(View v) {
for (int i = 0; i < list_pemesanan.getAdapter().getCount(); i++) {
View viewListPemesanan = list_pemesanan.getChildAt(i);
TextView txtNamaMenu = (TextView) viewListPemesanan.findViewById(R.id.txtNamaMasuk);
TextView txtJumlahMenu = (TextView) viewListPemesanan.findViewById(R.id.txtJumlahMasuk);
EditText txtNoMeja = (EditText)findViewById(R.id.txtNoMeja);
String masuk_namamenu = txtNamaMenu.getText().toString();
String masuk_jumlahmenu = txtJumlahMenu.getText().toString();
String masuk_nomeja = txtNoMeja.getText().toString();
// Toast.makeText(ListPemesanan_Activity.this, ""+cacad, Toast.LENGTH_LONG).show();
initializeData(masuk_namamenu,masuk_jumlahmenu,masuk_nomeja);
}
}
private void initializeData(String masuk_namamenu,String masuk_jumlahmenu,String masuk_nomeja) {
// TODO Auto-generated method stub
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5);
nameValuePairs.add(new BasicNameValuePair("nama_menu",masuk_namamenu));
nameValuePairs.add(new BasicNameValuePair("jumlah",masuk_jumlahmenu));
nameValuePairs.add(new BasicNameValuePair("no_meja",masuk_nomeja));
sendData(nameValuePairs);
}
private void sendData(ArrayList<NameValuePair> data) {
// TODO Auto-generated method stub
// 1) Connect via HTTP. 2) Encode data. 3) Send data.
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://nervousme.vacau.com/android/insert_pesanan_new.php");
httppost.setEntity(new UrlEncodedFormEntity(data));
HttpResponse response = httpclient.execute(httppost);
}
catch(Exception e)
{
Log.e("log_tag", "Error: "+e.toString());
}
}
};
submit_list_pemesanan.setOnClickListener(listener);
OnClickListener listener1 = new OnClickListener() {
@Override
public void onClick(View v) {
EditText txtNoMeja = (EditText)findViewById(R.id.txtNoMeja);
String masuk_nomeja = txtNoMeja.getText().toString();
// Toast.makeText(ListPemesanan_Activity.this, ""+cacad, Toast.LENGTH_LONG).show();
initializeData(masuk_nomeja);
}
private void initializeData(String masuk_nomeja) {
// TODO Auto-generated method stub
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5);
nameValuePairs.add(new BasicNameValuePair("no_meja",masuk_nomeja));
sendData(nameValuePairs);
}
private void sendData(ArrayList<NameValuePair> data) {
// TODO Auto-generated method stub
// 1) Connect via HTTP. 2) Encode data. 3) Send data.
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://nervousme.vacau.com/android/reservasi_nomeja.php");
httppost.setEntity(new UrlEncodedFormEntity(data));
HttpResponse response = httpclient.execute(httppost);
}
catch(Exception e)
{
Log.e("log_tag", "Error: "+e.toString());
}
}
};
关于为什么吐司没有出现的任何想法?