How to update Listview item position when i updating lisview
I creating dialog and into dialog given a list of items.and also on dialog
i have added search functionality.when i clicking on items its get correct
item position but when i search list its not updated with data items
rather i cant retrieve exactly clickable items. Following is my Code.
public void uploadFromDirve(View vi) {
    EditText et;
    //setContentView(R.layout.list_dialog);
    // TODO Auto-generated method stub
    listDialog = new Dialog(Project_Define_Activity.this);
    listDialog.setTitle("Select Item");
    LayoutInflater li = (LayoutInflater)
Project_Define_Activity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = li.inflate(R.layout.list_dialog, null, false);
    listDialog.setContentView(v);
    listDialog.setCancelable(true);
    //there are a lot of <span id="IL_AD7" class="IL_AD">settings</span>,
for dialog, <span id="IL_AD1" class="IL_AD">check</span> them all out!
    ListView list1 = (ListView) listDialog.findViewById(R.id.listview);
    adapter=new
ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,names);
    list1.setAdapter(adapter);
    et=(EditText)listDialog.findViewById(R.id.edit_Search);
    et.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence cs, int arg1, int arg2, int
arg3) {
            // When user changed the Text
            Project_Define_Activity.this.adapter.getFilter().filter(cs);
            adapter.notifyDataSetChanged();
        }
        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                int arg3) {
            // TODO Auto-generated method stub
        }
        @Override
        public void afterTextChanged(Editable arg0) {
            // TODO Auto-generated method stub
        }
    });
    //list1.setAdapter(new
ArrayAdapter<String>(Project_Define_Activity.this,android.R.layout.simple_list_item_1,names));
    //now that the dialog is set up, it's time to <span id="IL_AD2"
class="IL_AD">show</span> it
    list1.setOnItemClickListener(new OnItemClickListener(){
        @Override
        public void onItemClick(AdapterView<?> adapter, View arg1, final
int arg2,
                long arg3) {
            // TODO Auto-generated method stub
            AlertDialog.Builder builder = new
AlertDialog.Builder(Project_Define_Activity.this);
            builder.setMessage("Attach file "+arg2)
            .setPositiveButton("Attach ", new
DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    System.out.println("OK CLICKED");
                    Log.e("Selected", names.get(arg2));
                    fileflag = 1;
                    fileindex = arg2;
                    listDialog.cancel();
                    nameOfFile.setText(names.get(arg2));
                }
            });
            builder.setNegativeButton("cancel", new
DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.dismiss();
                    listDialog.cancel();
                }
            });
            AlertDialog alert = builder.create();
            alert.setTitle("Information");
            alert.show();
        }
    });
    listDialog.show();
}
 
No comments:
Post a Comment