shruti
shruti

Reputation: 1

changing text of edit box in list view on button click in android

I am using a ListView, in which i have inflated another layout template which contains 2 Images, an edit text, a correction button , and 2 more buttons, one of which is quick edit button and now I want on click on this quick edit button the edit text should become editable and the correction button should become visible. can u please help me.

From the comments, for easy reading:

mv.quick_edit = (ImageButton)convertView.findViewById
    (R.id.gateway_list_info_image_button_temp);     
mv.quick_edit.setOnClickListener(new View.OnClickListener() { 
 @Override 
 public void onClick(View v) { 
    MyViewHolder m = new MyViewHolder(); 
    m.correct_button.setVisibility(View.VISIBLE); 
    m.edit_text.setText("text changed"); 
 }
});

Upvotes: 0

Views: 453

Answers (1)

DSS
DSS

Reputation: 7259

in the adapter's getView method, i believe you have:

editText = (EditText)mView.findViewById(id here);
btnEdit= (Button)mView.findViewById(id here);

set the onClickListener() of the button in the getView method, and inside the onclick, set visibility to invisible or gone, for the other button you mentioned, and set the setEnabled method to true for the editText.

I hope this much clue helps.

EDIT:

For using a viewHolder in your code, please refer to this

Code Snippets:

if(convertView==null){

    // inflate the layout
    LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
    convertView = inflater.inflate(layoutResourceId, parent, false);

    // well set up the ViewHolder
    viewHolder = new ViewHolderItem();
    viewHolder.textViewItem = (TextView) convertView.findViewById(R.id.textViewItem);

    // store the holder with the view.
    convertView.setTag(viewHolder);

}else{
    // we've just avoided calling findViewById() on resource everytime
    // just use the viewHolder
    viewHolder = (ViewHolderItem) convertView.getTag();
}

It is after the else block that you define the onClickListeners and use viewHolder.editText.setVisibility(View.INVISIBLE)

Upvotes: 1

Related Questions