2014-01-20 30 views
0

我有一個包含一個TextView一個ListView,我需要放大按鈕點擊這個TextView的,但我不能這樣做,我什麼都試過重寫simplecursor適配器和覆蓋getview()方法,但couldn」牛逼放大按鈕點擊TextView的,按鈕列表視圖外,我的代碼是:放大列表視圖

這是ListView的佈局:

<?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" > 

    <CheckBox 
android:id="@+id/bt_rating" 
android:focusable="false" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="center_vertical" 
android:button="@android:drawable/btn_star" 
android:onClick="onclick"/> 

<TextView 
android:id="@+id/text1" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:textSize="@dimen/FontSizeInListView" 
android:gravity="right" 
/> 
</LinearLayout> 

編輯

adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder(){ 
       Binds the Cursor column defined by the specified index to the specified view 
     public boolean setViewValue(View view, Cursor cursor, int columnIndex){ 


      if(view.getId() == R.id.text1){ 
      tv=(TextView)view;   
      }}** 

所以這種方式,我得到的TextView,但肯定只有最後創建的一個將被渲染和縮放我做tv.settextsize(..) 但只有頁面上創建了最後的TextView將改變,因爲我只有一個的ID,這樣我怎麼能獲取所有文字瀏覽,而不僅僅是最後一個創建的?

+0

您將需要一個自定義列表適配器。如果你已經使用了,你可以發佈你的getView方法嗎? – Tenfour04

+0

是的,我發佈了它。 –

回答

0

在您的自定義適配器中,添加一個變量(使用public setters和getters)來表示縮放級別。在您的getView方法中,使用此變量來更改文本視圖的文本大小(只需在返回行之前添加該文本大小即可)必須始終將大小設置爲某些值,因爲視圖已被重用

然後, 。改變縮放級別,更改適配器的縮放變量,然後調用它的notifyDataSetChanged,迫使它呼籲所有看得到的意見getView(這是假設你的子類ArrayAdapter)

+0

我認爲它開始工作,我做了其他的事情,它開始工作..明天會看到..因爲在我的方法中,我有一個文本視圖變得越來越大,其他人一樣,但其餘的保持不變,將看到如何解決這個問題..但至少它的工作.. –

+0

如果你不在'getView'中修改它,你會有很多像你剛纔描述的不可預知的行爲。列表視圖定期回收視圖,這些視圖只是滾動屏幕以用作滾動到屏幕上的新視圖。當視圖被回收時,它只會改變你告訴它在'getView'中更改的內容。 – Tenfour04

+0

請檢查編輯; –

0

它的工作我做了什麼:

adapter =new SimpleCursorAdapter(this,R.layout.rating,cu,new String[]{"Title","Fav"}, new int[]{R.id.text1,R.id.bt_rating},CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); 
      //added in last update 
      adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder(){ 
        /** Binds the Cursor column defined by the specified index to the specified view */ 
       public boolean setViewValue(View view, Cursor cursor, int columnIndex){ 


        if(view.getId() == R.id.text1){ 
        tv=(TextView)view;  
        tv.setTextSize(SizeOfTextInListView); 
        } 

});

而在變焦按鈕:

//zoom in button click 
     final Button zoom_in_btn = (Button) findViewById(R.id.button_zoom_in); 
     zoom_in_btn.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
      if(Zoom_counter<10){ 
        SizeOfTextInListView= SizeOfTextInListView+Zoom_In_Out_value; 
        adapter.notifyDataSetChanged(); 
         Zoom_counter++; 


      } 
      } 
     }); 

它完美地工作..