列表视图如何操纵名单适配器项目视图对象 [英] List view how to manipulate objects of list adapter item View

查看:111
本文介绍了列表视图如何操纵名单适配器项目视图对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  adapterListView =新SpecialAdapter(getBaseContext(),列表中,R.layout.listview_layout,从,到); 。headerView =((LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE))膨胀(R.layout.jpos_ror_header,空,假);。footerView =((LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE))膨胀(R.layout.jpos_ror_footer,空,假);TextView的锡=(TextView中)headerView.findViewById(R.id.textViewTinValue);
TextView的textViewNameOfPayor =(TextView中)headerView.findViewById(R.id.textViewNameOfPayor);
TextView的textViewLocation =(TextView中)headerView.findViewById(R.id.textViewLocation);


  

下面是获得对象的ID从我的页眉和页脚我的code。我怎样才能让我的列表视图数据适配器没有onClick事件的看法。我想做的事情在看我的布局一些布局操作。


 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
     机器人:方向=横向>     <! - 这里是我的数据适配器将在列表视图中每个项目显示 - >    <的LinearLayout
    机器人:方向=垂直
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>
        < RelativeLayout的
              机器人:ID =@ + ID / relativeModeOfPaymentCheck
              机器人:layout_width =FILL_PARENT
              机器人:layout_height =WRAP_CONTENT
              机器人:背景=#000000>      <的LinearLayout
          机器人:ID =@ + ID / linearForCheck
          机器人:layout_width =FILL_PARENT
          机器人:layout_height =WRAP_CONTENT          机器人:layout_alignParentLeft =真
          机器人:方向=垂直
          机器人:paddingTop =5DP>          <的TextView
              机器人:ID =@ + ID / textViewModeOfPaymentCheckValue
              机器人:layout_width =WRAP_CONTENT
              机器人:layout_height =WRAP_CONTENT
              机器人:文字=支付价值的检查模式              机器人:layout_marginLeft =15dp
              机器人:文字样式=大胆
              机器人:文字颜色=#FFFFFF/>
     < / LinearLayout中>
          &所述;! - asdasda - >
          <的LinearLayout
              机器人:ID =@ + ID / linearForAmountModeOfPayment
              机器人:layout_width =FILL_PARENT
              机器人:layout_height =WRAP_CONTENT
              机器人:layout_alignParentLeft =真
              机器人:layout_below =@ + ID / linearCheckDate
              机器人:方向=横向
              机器人:weightSum =2>              < RelativeLayout的
                  机器人:ID =@ + ID / relativeBlock100
                  机器人:layout_width =FILL_PARENT
                  机器人:layout_height =WRAP_CONTENT
                  机器人:layout_marginLeft =15dp
                  机器人:layout_weight =1
                  机器人:背景=#000000>                  <的TextView
                      机器人:ID =@ + ID / textViewModAmountCheck
                      机器人:layout_width =WRAP_CONTENT
                      机器人:layout_height =WRAP_CONTENT
                      机器人:文字=金额
                      机器人:文字颜色=#FFFFFF/>
              < / RelativeLayout的>              < RelativeLayout的
                  机器人:ID =@ + ID / relativeBlock101
                  机器人:layout_width =FILL_PARENT
                  机器人:layout_height =WRAP_CONTENT
                  机器人:layout_weight =1
                  机器人:背景=#000000>                  <的TextView
                      机器人:ID =@ + ID / textViewModeOfPayCheckValue
                      机器人:layout_width =WRAP_CONTENT
                      机器人:layout_height =WRAP_CONTENT
                      机器人:layout_alignParentTop =真
                      机器人:layout_centerHorizo​​ntal =真
                      机器人:文字颜色=#FFFFFF/>
              < / RelativeLayout的>
          < / LinearLayout中>
          <! - 发出支票的名字 - >
          <的LinearLayout
              机器人:ID =@ + ID / linearForNameCheckIssued
              机器人:layout_width =FILL_PARENT
              机器人:layout_height =WRAP_CONTENT
              机器人:layout_alignParentLeft =真
              机器人:layout_below =@ + ID / linearForCheck
              机器人:方向=横向
              机器人:知名度=水涨船高
              机器人:weightSum =2>              < RelativeLayout的
                  机器人:ID =@ + ID / relativeBlock101
                  机器人:layout_width =FILL_PARENT
                  机器人:layout_height =WRAP_CONTENT
                  机器人:layout_marginLeft =15dp
                  机器人:layout_weight =1
                  机器人:背景=#000000>                  <的TextView
                      机器人:ID =@ + ID / textViewBankNameCheckIssued
                      机器人:layout_width =WRAP_CONTENT
                      机器人:layout_height =WRAP_CONTENT
                      机器人:文字=中华银行股份有限公司。
                      机器人:文字颜色=#FFFFFF/>
              < / RelativeLayout的>
          < / LinearLayout中>
          <! - CHECK NUMBER - >
          <的LinearLayout
              机器人:ID =@ + ID / linearCheckNumber
              机器人:layout_width =FILL_PARENT
              机器人:layout_height =WRAP_CONTENT
              机器人:layout_alignParentLeft =真
              机器人:layout_below =@ + ID / linearForNameCheckIssued
              机器人:知名度=水涨船高
              机器人:方向=横向>              <的TextView
                  机器人:ID =@ + ID / textViewCheckNumber
                  机器人:layout_width =WRAP_CONTENT
                  机器人:layout_height =WRAP_CONTENT
                  机器人:layout_marginLeft =15dp
                  机器人:文字=#CHECK
                  机器人:文字颜色=#FFFFFF/>              <的TextView
                  机器人:ID =@ + ID / textViewCheckNumValue
                  机器人:layout_width =WRAP_CONTENT
                  机器人:layout_height =WRAP_CONTENT
                  机器人:文字颜色=#FFFFFF/>
          < / LinearLayout中>
         <! - 支票日期 - >
          <的LinearLayout
              机器人:ID =@ + ID / linearCheckDate
              机器人:layout_width =FILL_PARENT
              机器人:layout_height =WRAP_CONTENT
              机器人:layout_alignParentLeft =真
              < - 机器人:知名度=水涨船高 - >
              机器人:layout_below =@ + ID / linearCheckNumber
              机器人:方向=横向>              <的TextView
                  机器人:ID =@ + ID / textViewCheckDate
                  机器人:layout_width =WRAP_CONTENT
                  机器人:layout_height =WRAP_CONTENT
                  机器人:layout_marginLeft =15dp
                  机器人:文字=检查日期
                  机器人:文字颜色=#FFFFFF/>              <的TextView
                  机器人:ID =@ + ID / textViewCheckDateValue
                  机器人:layout_width =WRAP_CONTENT
                  机器人:layout_height =WRAP_CONTENT
                  机器人:文字颜色=#FFFFFF/>
          < / LinearLayout中>
        <的LinearLayout
              机器人:ID =@ + ID / linearLineForCheck
              机器人:layout_width =WRAP_CONTENT
              机器人:layout_height =2DP
              机器人:layout_alignParentLeft =真
              机器人:layout_below =@ + ID / linearForAmountModeOfPayment
              机器人:方向=横向>                  <查看
                      机器人:ID =@ + ID / View201
                      机器人:layout_width =WRAP_CONTENT
                      机器人:layout_height =WRAP_CONTENT
                      机器人:背景=#FFFFFF/>
          < / LinearLayout中>
          < / RelativeLayout的>
          < / LinearLayout中>
< / LinearLayout中>


  

在此适配器我想有操纵linearlayouts观 LinearLAyout.setVisibility(LinearLayout.GONE或可见);


  
  

下面我想我有一些铅来自人士Himanshu的回答我的问题。这里是有问题的ListView我特殊的适配器IM如何获取视图和执行的ViewGroup到我的特殊的适配器,这里是我SpecialAdapter ..


 公共类SpecialAdapter扩展SimpleAdapter {
    公共静态TextView的电视;
    私人诠释[] =颜色INT新[] {0xffcccccc,为0xffffffff};
    私人诠释[] = colors2新INT [] {为0xffffffff,0xff000000};
   //上下文的背景下;
    公共SpecialAdapter(上下文的背景下,列表与LT; HashMap的<字符串,字符串>>的项目,INT资源的String []从,INT []到){
        超(背景下,项目,资源,从,到);
    }    @覆盖
    公共查看getView(INT位置,查看convertView,父母的ViewGroup){
      查看查看= super.getView(位置,convertView,父母);
      INT colorPos =位置%colors.length;
      view.setBackgroundColor(颜色[colorPos]);
      // TextView中的TextView =(TextView中)view.findViewById(R.id.textViewModAmountCheck);
      //textView.setText(\"AlvinTest);
      返回视图。
    }


  

能anyoune告诉我,我在做正确时,即时通讯实现毫克getView2。


 公开查看getView2(上下文的背景下,INT位置,查看convertView,父母的ViewGroup){
        LayoutInflater layoutInflater = LayoutInflater.from(上下文); //获取布局充气;// LayoutInflater INF = LayoutInflater.from(的getContext());
        如果(convertView == NULL){
            convertView = layoutInflater.inflate(R.layout.listview_layout,NULL);
        }
        的LinearLayout YYY =(的LinearLayout)convertView.findViewById(R.id.linearCheckDate);
        yyy.setVisibility(View.GONE);
        返回convertView;
    }
    公共布尔setViewValue(查看视图,光标光标,诠释参数:columnIndex){
        INT getIndex = cursor.getColumnIndex(名称);
        字符串empname = cursor.getString(getIndex);
        电视=(TextView的)视图。
        tv.setTextColor(Color.WHITE);
        tv.setText(empname);
        如果(empname.equals(任何字符串))
        {
            tv.setTextColor(Color.rgb(58,58,224));
            返回true;
        }
        返回false;
    }
}


  

下面是我的code时,即时通讯从我listAdapter调用getView2


  LayoutInflater INF = LayoutInflater.from(本);
视图V = inf.inflate(R.layout.listview_layout,NULL);//此处加魔法BU我不知道我怎样才能得到这些观的ViewGroup的视图
查看itemConvertView = inf.inflate(R.layout.listview_layout,NULL);
ViewGroup中listParent = NULL; //this.getParent();//(ViewGroup)SelectorView.this.getParent();//空;
adapterListView.getView2(这一点,0,itemConvertView,listParent);


解决方案

我从你的问题理解的是,有一个在您ListView项一些人认为要在需要时才会显示。您可以在适配器的getView方法,你夸大列表项的自定义布局做到这一点。类似下面

 公共查看getView(INT位置,查看convertView,父母的ViewGroup){
    LayoutInflater layoutInflater =得到您的布局充气;    如果(convertView == NULL){
        convertView = layoutInflater.inflate(R.layout.XXXX,NULL);
    }
    的LinearLayout YYY =(的LinearLayout)convertView.findViewById(R.id.member_name_text_view);
    yyy.setVisibility(View.Gone)
    返回convertView;
}

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);  

解决方案

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;
}

这篇关于列表视图如何操纵名单适配器项目视图对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆