2012-12-07 28 views
-1

相同的ID我创建使用XML和添加编辑文本提交,在列表视图中的适配器类.IM使用enumerator.by这我能创建两个文本框与同样id.the问题是如何从文本字段得到的字符串,因为它们共享相同的id.below是代码。如何从多个编辑文本的文本与机器人

@Override 
public View getView(final int position, View convertView, ViewGroup parent) { 
    View rowView = null; 

    AddKeywordRow row = keywordRows.get(position); 

    switch (row.getRowType()) { 
    case TitleRow: 
     rowView = inflater.inflate(R.layout.titlerow, null); 
     TextView txtTitle = (TextView) rowView.findViewById(R.id.rowtitle); 
     txtTitle.setText(row.getMessage()); 
     break; 
    case EditRow: 
     rowView = inflater.inflate(R.layout.editrow, null); 
     txtInput = (EditText) rowView.findViewById(R.id.rowedit); 
     txtInput.setHint(row.getMessage()); 
     if (row.getHeight() != 0) 
     { 
      LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
        LinearLayout.LayoutParams.MATCH_PARENT,row.getHeight()); 
      txtInput.setLayoutParams(layoutParams); 
      layoutParams.setMargins(7, 0, 7,0); 
     //txtInput.setLayoutParams(new LinearLayout.LayoutParams(
      //  LinearLayout.LayoutParams.MATCH_PARENT, row.getHeight())); 
      txtInput.setPadding(3,0,0,30); 
     } 
     // set padding and margin 
     break; 
    case MessageRow: 
     rowView = inflater.inflate(R.layout.messagerow, null); 
     TextView txtMessage = (TextView) rowView 
       .findViewById(R.id.rowmessage); 
     txtMessage.setText(row.getMessage()); 
     break; 
    case ButtonRow: 
     rowView = inflater.inflate(R.layout.buttonrow, null); 
     Button btn = (Button)rowView.findViewById(R.id.button1); 

     btn.setOnClickListener(new OnClickListener() { 


     } 
     }); 

     break; 
    } 

    return rowView; 
} 
+0

有没有简单的方法来做到这一点,我认为。你必须通过你的listview中的每一个孩子,并检查它是否有这个ID,如果这是你想要的方法。也许可以考虑使用别的东西,然后列表视图这..这并不意味着使用这种方式。但是,就是要用来创建相同的项目列表..喜欢用表格数据的表。使用上述code..would –

回答

0

首先,我会建议您使用Holder pattern作为您的列表项。 其次重写getItem(int position);在您的适配器中,以便根据位置返回必要的文本值。例如,您可以在您的活动中的onItemclickListener()中使用它。

@Override 
    public String getItem(int position) { 
     return keywordRows.getMessage(position); 
    } 

而且你onItemClickListener看起来像:

((EditText上)getAdapter()的getItem(ID):

private AdapterView.OnItemClickListener mItemClickListener = new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> adapterView, View view, int position, long rowid) { 
      String message = (String)adapterView.getItemAtPosition(position); 
     } 
    } 
+0

k将尝试这种 – user578386

0

通过列表行,像(伪代码)进行检索).getText()

+0

可以ü给我的这一个例U grateful..i希望将其存储在两个不同的字符串 – user578386