List view how to manipulate objects of list adapter item View

一个人想着一个人 提交于 2019-12-23 04:50:33

问题


adapterListView = new SpecialAdapter(getBaseContext(),list,R.layout.listview_layout,from,to);       

 headerView = ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.jpos_ror_header, null, false);

footerView = ((LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.jpos_ror_footer, null, false); 



TextView tin=(TextView)headerView.findViewById(R.id.textViewTinValue);       
TextView textViewNameOfPayor=(TextView)headerView.findViewById(R.id.textViewNameOfPayor);        
TextView textViewLocation=(TextView)headerView.findViewById(R.id.textViewLocation);

Here is my code in getting object id's from my header and footer. how can i get the view of my list view data adapter without onClick event. i want to do some layout manipulation in viewing of my layout.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     android:orientation="horizontal"  >

     <!-- here is my data adapter to be display per item in list view  -->  

    <LinearLayout 
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
        <RelativeLayout
              android:id="@+id/relativeModeOfPaymentCheck"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:background="#000000" >

      <LinearLayout
          android:id="@+id/linearForCheck"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"

          android:layout_alignParentLeft="true"
          android:orientation="vertical"
          android:paddingTop="5dp" >

          <TextView
              android:id="@+id/textViewModeOfPaymentCheckValue"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Mode of Payment Value check"

              android:layout_marginLeft="15dp"
              android:textStyle="bold"
              android:textColor="#ffffff" />        
     </LinearLayout>
          <!-- asdasda -->
          <LinearLayout
              android:id="@+id/linearForAmountModeOfPayment"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_alignParentLeft="true"
              android:layout_below="@+id/linearCheckDate"
              android:orientation="horizontal"
              android:weightSum="2" >

              <RelativeLayout
                  android:id="@+id/relativeBlock100"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginLeft="15dp"
                  android:layout_weight="1"
                  android:background="#000000" >

                  <TextView
                      android:id="@+id/textViewModAmountCheck"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="AMOUNT"
                      android:textColor="#ffffff" />
              </RelativeLayout>

              <RelativeLayout
                  android:id="@+id/relativeBlock101"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_weight="1"
                  android:background="#000000" >

                  <TextView
                      android:id="@+id/textViewModeOfPayCheckValue"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_alignParentTop="true"
                      android:layout_centerHorizontal="true"
                      android:textColor="#ffffff" />
              </RelativeLayout>
          </LinearLayout>
          <!-- name of check issued -->
          <LinearLayout
              android:id="@+id/linearForNameCheckIssued"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_alignParentLeft="true"
              android:layout_below="@+id/linearForCheck"
              android:orientation="horizontal"
              android:visibility="gone"
              android:weightSum="2" >

              <RelativeLayout
                  android:id="@+id/relativeBlock101"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginLeft="15dp"
                  android:layout_weight="1"
                  android:background="#000000" >

                  <TextView
                      android:id="@+id/textViewBankNameCheckIssued"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="RIZAL COMMERCIAL BANKING CORP."
                      android:textColor="#ffffff" />
              </RelativeLayout>
          </LinearLayout>


          <!-- CHECK NUMBER -->
          <LinearLayout
              android:id="@+id/linearCheckNumber"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_alignParentLeft="true"
              android:layout_below="@+id/linearForNameCheckIssued"
              android:visibility="gone"
              android:orientation="horizontal" >

              <TextView
                  android:id="@+id/textViewCheckNumber"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginLeft="15dp"
                  android:text="CHECK # : "
                  android:textColor="#ffffff" />

              <TextView
                  android:id="@+id/textViewCheckNumValue"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:textColor="#ffffff" />
          </LinearLayout>
         <!-- CHECK DATE -->
          <LinearLayout
              android:id="@+id/linearCheckDate"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_alignParentLeft="true"
              <!-- android:visibility="gone" -->
              android:layout_below="@+id/linearCheckNumber"
              android:orientation="horizontal" >

              <TextView
                  android:id="@+id/textViewCheckDate"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginLeft="15dp"
                  android:text="CHECK DATE : "
                  android:textColor="#ffffff" />

              <TextView
                  android:id="@+id/textViewCheckDateValue"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:textColor="#ffffff" />
          </LinearLayout> 


        <LinearLayout
              android:id="@+id/linearLineForCheck"
              android:layout_width="wrap_content"
              android:layout_height="2dp"
              android:layout_alignParentLeft="true"
              android:layout_below="@+id/linearForAmountModeOfPayment"
              android:orientation="horizontal" >

                  <View
                      android:id="@+id/View201"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:background="#ffffff" />
          </LinearLayout>  


          </RelativeLayout>
          </LinearLayout>
</LinearLayout>

in this adapter i want to manipulate the view of linearlayouts by having LinearLAyout.setVisibility(LinearLayout.GONE or VISIBLE);

Here i think i have some lead from my problem from the answer of himanshu. here is my listview special adapter im having problem how can get the view and viewGroup implementation to my special adapter here is my SpecialAdapter..

public class SpecialAdapter extends SimpleAdapter {
    public static TextView tv;
    private int[] colors = new int[] { 0xffcccccc , 0xffffffff };
    private int[] colors2 = new int[] { 0xffffffff , 0xff000000 }; 
   // Context context;
    public SpecialAdapter(Context context, List<HashMap<String, String>> items, int resource, String[] from, int[] to) {
        super(context, items, resource, from, to);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      View view = super.getView(position, convertView, parent);
      int colorPos = position % colors.length;
      view.setBackgroundColor(colors[colorPos]);
      //TextView textView = (TextView)view.findViewById(R.id.textViewModAmountCheck);
      //textView.setText("AlvinTest");
      return view;
    }

Could anyoune tell me i am doing right when im implementing mg getView2.

    public View getView2(Context context, int position, View convertView, ViewGroup parent) {
        LayoutInflater layoutInflater = LayoutInflater.from(context);//get your layout inflator;

//LayoutInflater inf = LayoutInflater.from(getContext());
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.listview_layout, null);
        }
        LinearLayout yyy = (LinearLayout) convertView.findViewById(R.id.linearCheckDate);
        yyy.setVisibility(View.GONE);
        return convertView;
    }




    public boolean setViewValue(View view, Cursor cursor, int columnIndex){    
        int getIndex = cursor.getColumnIndex("Name");
        String empname = cursor.getString(getIndex);
        tv = (TextView) view;
        tv.setTextColor(Color.WHITE);
        tv.setText(empname);
        if(empname.equals("Any String"))
        {                   
            tv.setTextColor(Color.rgb(58, 58, 224));
            return true;
        }
        return false;           
    }
}

Here's my code when im calling the getView2 from my listAdapter

LayoutInflater inf = LayoutInflater.from(this);
View v = inf.inflate(R.layout.listview_layout, null);

//add magic here bu i don't know how can i get the view of these View and ViewGroup
View itemConvertView = inf.inflate(R.layout.listview_layout, null);
ViewGroup listParent =null; //this.getParent();//(ViewGroup)SelectorView.this.getParent();// null;
adapterListView.getView2(this,0, itemConvertView, listParent);  

回答1:


try this: Hide your Layout:

YourLayout.setVisibility(View.GONE);

Visible your Layout :

YourLayout.setVisibility(View.VISIBLE);



回答2:


If i understood your problem correctly, you want to get the first element of the ListView pro grammatically and change its state (Visibility).

You can get the element in ListView by calling getChildAt(int index) method e.g

LinearLayout yourFirstView = (LinearLayout) listview.getChildAt(0);

Accessing child of the element that reside in first row of the listview.

ViewType view = (ViewType)yourFirstView.findViewById(R.id.elementId);

setting the visiblity

yourFirstView.setVisiblity(View.Gone); // or View.VISIBLE



回答3:


What I understand from your question is that there is some view in your ListView item which you want to show only if needed. You can do this in the getView method of your adapter where you inflate the custom layout of list item. Something like below

public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater layoutInflater = get your layout inflator;

    if (convertView == null) {
        convertView = layoutInflater.inflate(R.layout.XXXX, null);
    }
    LinearLayout yyy = (LinearLayout) convertView.findViewById(R.id.member_name_text_view);
    yyy.setVisibility(View.Gone)
    return convertView;
}


来源:https://stackoverflow.com/questions/21447659/list-view-how-to-manipulate-objects-of-list-adapter-item-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!