2014-01-30 22 views
0
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); 

對象這是我在獲得對象的ID從我的頁眉和頁腳代碼。我怎樣才能得到我的列表視圖數據適配器沒有onClick事件的看法。我想在查看我的佈局時進行一些佈局操作。列表視圖如何操作的列表適配器項查看

<?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> 
在此適配器我想操縱linearlayouts的觀點

具有LinearLAyout.setVisibility(LinearLayout.GONE or VISIBLE);

這裏我覺得我有一些鉛從人士Himanshu的回答我的問題。這裏是有問題怎麼能得到的視圖和執行的ViewGroup我這裏特殊的適配器列表視圖我的專用適配器IM是我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; 
    } 

能anyoune告訴我,我在做正確的即時通訊時執行毫克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;   
    } 
} 

這裏是我的代碼時,我可是從我listAdapter調用getView2

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

LinearLAyout.setVisibility(View.GONE or VISIBLE);嘗試像這樣... – NagarjunaReddy

+0

我想要的是在列表視圖顯示項目之前操作佈局項目。 – DreamBigAlvin

+0

然後在原始 – keshav

回答

0

試試這個: 隱藏您的佈局:

YourLayout.setVisibility(View.GONE); 

可見您的佈局:

YourLayout.setVisibility(View.VISIBLE); 
+0

我想在執行操作之前先從列表視圖中獲取視圖那..我知道.. – DreamBigAlvin

+0

我想獲得清單視圖項目的視圖 – DreamBigAlvin

+0

清楚地解釋你的任務... – balaji

0

如果我正確地理解了您的問題,您希望在語法上獲得ListView pro的第一個元素並更改其狀態(可見性)。

你可以通過調用getChildAt(int index)方法 e.g

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

訪問駐留在列表視圖中的第一行元素的子得到的ListView的元素。

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

設置可視性

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

每個元素的ListView我想獲得佈局對象的塊在那裏。我怎麼能從適配器調用我的對象的視圖的特定id資源..? – DreamBigAlvin

+0

看看我的headerView代碼,我使用headerView.findViewById(R.id.textViewTinValue)實例化了TextView。像這樣的程序... – DreamBigAlvin

+0

我有我的xml數據適配器。這是我想要操縱的數據。每個列表項都包含整個xml數據適配器。我怎樣才能調用指定的視圖和資源索引的那些線性佈局我想操縱...? – DreamBigAlvin

0

我從你的問題怎樣理解的是,有你的ListView項一些人認爲要在需要時纔會顯示。您可以在適配器的getView方法中執行此操作,在該方法中充氣列表項的自定義佈局。像下面的東西

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

我該如何稱此類?我怎麼能得到視圖和ViewGroup的參數..我真的不知道如何實現這一點。但我也嘗試過這樣的事情,但它沒有參數View和ViewGroup .. – DreamBigAlvin