簡體   English   中英

android列表查看項

[英]android list view items

我有一個ListView,我為列表中的項目創建了一個custom_row,每行包含2個TextView的名稱(textView1和textView2)和一個ImageView,當我單擊一個項目時,出現AlertDialog,那里有輸入文本,確定,取消按鈕。 在alertdialog的輸入中輸入某些內容並單擊確定之后,我想從我單擊的ListView中的項目中修改textView2。 我怎樣才能做到這一點?

list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

      public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {

        TextView tv=new TextView(getApplicationContext());
        //Log.i("da","Clicked : "+labelData[position]);
        setLabel(labelData[position]);
        tv=(TextView)findViewById(R.id.textView2);
        tv.setText("das");


      }

 public void setLabel(String poz){

     AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
     alertDialog.setTitle("Set "+poz);
     alertDialog.setMessage("Enter "+poz);
     final EditText input = new EditText(this);
     alertDialog.setView(input);
     alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int whichButton) {
           String value = input.getText().toString();
           Log.i("da","Clicked : "+value);
           }
         });

     alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int whichButton) {
             // Canceled.
           }
         });

     alertDialog.show();
}

您正在尋找的是從調用的活動中獲取結果。 總之,以下是在父活動中實現的方法:1. startActivtyForResult(...)2. onActivityResult(...)

子Activity應該照常完成工作並最終調用:1. setResult(...)2. finish()

您可以在此處了解更多信息: http : //saigeethamn.blogspot.com/2009/08/android-developer-tutorial-for_31.html

單擊OK,您就可以從Edittext(在您的情況下輸入)中獲取String ,還可以Position 。現在只需在數組中設置String,我的意思是刪除在textview2中的setText中使用的舊字符串,然后添加它。然后adapter.notifyDatasetChanged();您應該使用動態數組從Alert中刪除或添加String值。我的意思是...

        List<String> list = new ArrayList<String>();

        list.remove(position);
        list.set(position,YourAlertTextfiledValue);

        list.get(position);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM