2

我想在我的应用程序中先输入一些文本,然后,当用户单击屏幕键盘上的完成按钮(使用 android:imeOptions="actionSearch")时,Isome 数据将从此 url 显示:

("http://www.aaaa.com/selectAgent.htm?n="+cari_agen);

但是当我进行一些处理时,什么也没有发生,我的代码仍然加载所有数据,而不是具体为 cari_agen,这是我的源代码:

public class MainActivity extends Activity {
GridView gridView;
private static final String ATASAN = "atasan";
private static final String KODE_AGEN = "kode_agen";
private static final String JENIS = "jenis";
private static final String NO_AAJI = "no_aaji";
private static final String NAMA_AGEN = "nama_agen";

List AgenList = new ArrayList();
boolean boolStatusKoneksi=true;
private ProgressDialog Dialog;
protected Context applicationContext;
EditText cari;
SearchView search;


@Override
public void onCreate(Bundle savedInstanceState){

    super.onCreate(savedInstanceState);     
    setContentView(R.layout.mainmenu);

    search=(SearchView) findViewById(R.id.searchView1);
    cari=(EditText) findViewById(R.id.search);

    cari.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_SEARCH) {
        new AgenAsyncTask().execute();
        return true;
    }
    return false;
     }
   });

}

public class AgenAsyncTask extends AsyncTask<String, String, String>
{
    String cari_agen = cari.getText().toString();
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        Dialog = new ProgressDialog(MainActivity.this);
        Dialog.setMessage("Mohon Tunggu sebentar...");
        Dialog.setIndeterminate(false);
        Dialog.setCancelable(true);
        Dialog.show();
    }


    protected String doInBackground(String... args) {
    String url =("http://www.aaaa.com/selectAgent.htm?n="+cari_agen);
              try{
                  JSONParser j=new JSONParser();
                    JSONArray jsonArray = j.takeJson(url);

                  for(int i =0; i<jsonArray.length(); i++)
                  {
                  JSONObject c  = jsonArray.getJSONObject(i);
                        HashMap<String, String> map = new HashMap<String, String>();
                        if (c.has("nama_agen")) 
                        Log.v(NAMA_AGEN,"Nama agen=") ;
                        map.put("nama_agen", c.get("nama_agen").toString());
                        if (c.has("atasan")) 
                            map.put("atasan", c.get("atasan").toString());
                        if (c.has("jenis")) 
                            map.put("jenis", c.get("jenis").toString());
                          AgenList.add(map);
                            if (c.has("no_aaji")) 
                                map.put("no_aaji", c.get("no_aaji").toString());
                     }
                } catch (JSONException e) {
                    e.printStackTrace();
                    }
              return null;
                }




@Override
protected void onPostExecute(String arg)
{
Dialog.dismiss();
GridView gridview = (GridView) findViewById(R.id.gridview);
ListAdapter adapter = new SimpleAdapter(
    MainActivity.this, AgenList, R.layout.list_item,
    new String[] { NAMA_AGEN, ATASAN, JENIS,NO_AAJI }, new int [] {R.id.nama_agen, R.id.atasan, R.id.jenis,R.id.no_aaji});
gridview.setAdapter(adapter);   }

我希望有人能帮我解决这个问题,谢谢你

4

0 回答 0