Skip to content Skip to sidebar Skip to footer

Setvisitility Item In Custom Listview

I have a problem now! I have custom ListView, there I have two TextView element. I want setVisibility(TextView.gone) for one TextView in ListView element. I don't know how to do i

Solution 1:

In your adapter you can try this code to hide the second textview.

public View getView(int position, View convertView, ViewGroup parent){
       convertView = mInflater.inflate(R.layout.your_custom_list_layout, null);
    TextViewtextOne= (TextView)convertView.findViewById(R.id.txtOne);
    TextViewtextTwo= (TextView)convertView.findViewById(R.id.txtTwo);

    textTwo.setVisibility(View.GONE);

    return convertView;
} 

ADDED: you can add a boolean that toggles inside your onClick() then modify the getView();

booleanhideTextTwo=false;

    onClick(View v){
      hideTextTwo = true;
      yourAdapter.notifyDatasetChanged();

    }


public View getView(int position, View convertView, ViewGroup parent){
    convertView = mInflater.inflate(R.layout.your_custom_list_layout, null);
    TextViewtextOne= (TextView)convertView.findViewById(R.id.txtOne);
    TextViewtextTwo= (TextView)convertView.findViewById(R.id.txtTwo);

if(hideTextTwo){
    textTwo.setVisibility(View.GONE);
}

    return convertView;
}

Solution 2:

//in your adapter

public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            inflater = context.getLayoutInflater();
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.list_row, null);
            holder.first_line=(TextView) convertView.findViewById(R.id.textview_row1);

            holder.second_line=(TextView) convertView.findViewById(R.id.second_row);

            convertView.setTag(holder);
        }


//TODO: hiding the first_line in the listview 
            holder.first_line.setVisibility(View.GONE);
            holder.second_line.setText("");
return (convertView);
        }

Post a Comment for "Setvisitility Item In Custom Listview"