I have a ListView
which has a custom cell in it with 2 buttons
, a label
and an editText
. I've got it so that when I click the button for the custom cell it does a log saying at what position the button has been pressed. However I can't work out how I make it so when I press the button, it changes the text in the textbox for that cell. I can't work out how to reference it at a position.
My XML is:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/lvItems"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:drawSelectorOnTop="false" >
</ListView>
</RelativeLayout>
My Code:
class CustomAdapter extends BaseAdapter
{
@Override
public int getCount() {
return mDescription.size();
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return 0;
}
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
LayoutInflater inf=getLayoutInflater();
View v=inf.inflate(R.layout.noncriticalasset, arg2,false);
TextView tv=(TextView)v.findViewById(R.id.txtOption);
final EditText et =(EditText)v.findViewById(R.id.tbAnswer);
Button btPlus=(Button)v.findViewById(R.id.btnPlus);
Button btMinus=(Button)v.findViewById(R.id.btnMinus);
btMinus.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
int position = listView
.getPositionForView((View) v.getParent());
Log.v("Position id", "" + position);
et.setText("Test Text");
notifyDataSetChanged();
} catch (Exception e) {
Log.e("error", "error" + e.getMessage());
}
}
});
tv.setText(mDescription.get(arg0).toString());
return v;
}
I tried referencing the textbox with just an et.setText()
but it didn't work. Is there a way to say atPosisiton.et.setText
etc?
Thanks a lot.