2013-07-05 41 views
0

我有一個列表與textview,許多數據的列表中流動,並有一個textview在XML ....問題是我想更新列表中的每個textview條目..我想更新( TAG_QTY)列表的TextView當每一個值項...想要更新每個條目視圖中的列表?

ListAdapter adapter = new SimpleAdapter(this, contactList, 
      R.layout.list_item, 
      new String[] { TAG_BARCODE, TAG_DIVISION, TAG_MRP,TAG_QTY}, new int[] { 
        R.id.txt, R.id.txt1, R.id.mrp,R.id.qty1 }); 
    setListAdapter(adapter); 
    // selecting single ListView item 
    ListView lv = getListView(); 

    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
    @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 

      //String name = ((TextView) view.findViewById(R.id.qty1)).getText().toString(); 
      LayoutInflater li = LayoutInflater.from(context); 
      View promptsView = li.inflate(R.layout.prompts, null); 
      //final View textEntryView; 

      AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
        context); 

      // set prompts.xml to alertdialog builder 
      alertDialogBuilder.setView(promptsView); 
      fourth = (TextView)findViewById(R.id.qty1); 
      userInput = (EditText)promptsView.findViewById(R.id.editTextDialogUserInput); 
      //String ed = userInput.getText().toString(); 
      //final int ed= Integer.parseInt(userInput.getText().toString()); 
      alertDialogBuilder 
        .setCancelable(false) 
        .setPositiveButton("OK", 
          new DialogInterface.OnClickListener() { 
           public void onClick(DialogInterface dialog,int id) { 
            String ed = userInput.getText().toString().trim(); 
            fourth.setText(ed); 
          } 
          }) 
        .setNegativeButton("Cancel", 
          new DialogInterface.OnClickListener() { 
           public void onClick(DialogInterface dialog,int id) { 
            dialog.cancel(); 
           } 
          }); 

      // create alert dialog 
      AlertDialog alertDialog = alertDialogBuilder.create(); 
      alertDialog.show(); 

     } 
    } 
    ); 
+0

你的問題還不清楚。你想在每次新條目後刷新列表嗎? –

+0

不......如果我點擊列表中的一個視圖想要編輯列表中的textview .. – MrSyntax

+0

以列表視圖的id爲要編輯的文本視圖的子項,然後在該視圖中更改查找id你的textview字段,並設置新的文字。 –

回答

1

爲了獲取列表視圖孩子

lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
    @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 

     View c = lv.getChildAt(position); 
     // c is your list view child which is clicked 
     final TextView tv = (TextView) c.findViewById(R.id.qty1); 
     // tv is your textview of whom vwlue you have to change. 
     //changes the value of textview here and den notify data set changed and refresh the list.   
     } 
    });  
相關問題