2012-12-09 22 views
9

Vì vậy, đây là thỏa thuận này, tôi đã cố gắng nhìn vào chủ đề khác như thế này đây https://stackoverflow.com/questions/12479909/how-to-make-list-header-and-footer-not-click-able Làm thế nào để làm cho listFooter không thể nhấp

Nhưng nó không hoạt động. Tôi không thể quản lý để "không làm gì khi nhấp chuột". Nhưng vấn đề không phải là để xử lý những gì hapens khi danh sách được nhấp, đó là danh sách được đưa ra phản hồi như thể nó đã được nhấp (IE sáng lên), và tôi không muốn điều đó.

Tôi không hiểu tại sao các phần bên dưới không hoạt động (IE nó vẫn còn có thể lựa chọn/nhấp chuột được)

ViewGroup footer = (ViewGroup)inflater.inflate(R.layout.listview_footer_row, null, false);//This is not working as it should 
     listView.addFooterView(footer); 

Bất cứ ai có bất cứ ý tưởng tại sao chân của tôi là có thể click/lựa chọn mặc dù tôi thêm te Statment sai phương pháp?

Đây là mã của tôi

import java.util.ArrayList; 

import android.content.Intent; 
import android.annotation.SuppressLint; 
import android.app.Fragment; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.ViewGroup; 
import android.widget.AdapterView; 
import android.widget.AdapterView.OnItemClickListener; 
import android.widget.Button; 
import android.widget.ListView; 

public class PortfolioFragMent extends Fragment{ 

    private ListView listView; 
    private Button goButton; 
    private String[] listheader = {"Idag","Senaste","Antal","Avkastning %","Avkastning","Tot Värde"}; 
    private static ShareHoldingAdapter adapter; 
    private int totalElemInlist = listheader.length; 
    private int currentelemInList=0; 
    private ArrayList<ShareHolding> allShareHoldings = new ArrayList<ShareHolding>(); 
    private Button buyButton; 

    @SuppressLint("NewApi") 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 


    } 

    @SuppressLint({ "NewApi", "NewApi" }) 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ 
     allShareHoldings = Portfolio.getPortfolio().getAllShareHoldings(); 

     super.onCreate(savedInstanceState); 
     View view = inflater.inflate(R.layout.portfolioframe, container, false);  
     listView = (ListView)view.findViewById(R.id.listView1); 
     String[] array = new String[] {"one", "two", "three"}; 
     /**********************************/ 
     adapter = new ShareHoldingAdapter(getActivity(), R.layout.listview_item_row, allShareHoldings); 
     /***********************************/ 

     ViewGroup header = (ViewGroup)inflater.inflate(R.layout.listview_header_row, null, false); 
     ViewGroup footer = (ViewGroup)inflater.inflate(R.layout.listview_footer_row, null, false);//This is not working as it should 
     listView.addHeaderView(header); 
     listView.addFooterView(footer); 

     goButton = (Button)view.findViewById(R.id.testButton); 
     goButton.setText(listheader[currentelemInList]); 

     listView.setAdapter(adapter); 
     goButton.setOnClickListener(new OnClickListener() { 
      public void onClick(View view) { 
       String buttonPressed = (String) ((Button) view).getText(); 
       currentelemInList++; 
       if(currentelemInList>=totalElemInlist){ 
        currentelemInList=0; 
       } 
       adapter.setButtonPressed(currentelemInList); 
       goButton.setText(listheader[currentelemInList]); 
      } 
     }); 

     listView.setOnItemClickListener(new OnItemClickListener() { 
      public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) { 
       /* 
       * Have to catch Nullpointer exception here since I have two elements in list plus 1 header and 1 footer. 
       * When I click the footer I sent the number 3 to my next intent (4-1). But I don't want the footer to fire on click at all 
       */ 
       if(position<Portfolio.getPortfolio().count()){//Just to check that I havn't clicked listFooter. 
       System.out.println("Klicka i listan"); 
       Intent intent = new Intent(getActivity().getApplicationContext(), 
       DetailShareHoldingActivity.class); 
       intent.putExtra("new_variable_name","value"); 
       intent.putExtra("bookPositionInList",(position-1));//Just so that the top of the list is not clicked 
       System.out.println(position); 

       startActivity(intent); 
       } 
      } 
     }); 

     buyButton = (Button)view.findViewById(R.id.buyNewShares); 
     buyButton.setOnClickListener(new OnClickListener() {public void onClick(View view) { 

      buyShares(); 

     }}); 
     return view;  
    } 

    @SuppressLint({ "NewApi", "NewApi" }) 
    private void buyShares(){ 
      System.out.println("Köpt tryckt"); 
     Intent intent = new Intent(getActivity().getApplicationContext(), 
       BuyNewSharesActivity.class); 
       startActivity(intent); 
     } 

    @SuppressLint({ "NewApi", "NewApi" }) 
    public void onListItemClick(ListView l, View v, int position, long id) { 
     System.out.println("Klicka i listan"); 
     Intent intent = new Intent(getActivity().getApplicationContext(), 
     DetailShareHoldingActivity.class); 
     intent.putExtra("new_variable_name","value"); 
     intent.putExtra("bookPositionInList",position); 
     startActivity(intent); 
    } 
     public static ShareHoldingAdapter getPortfolioFragmentShareHoldingAdapter(){ 
      return adapter; 
     } 
} 

Và đây là tập tin listview_footer_row.xml tôi

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
     <TableLayout 
      android:id="@+id/book_detailTable" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="top" 
      android:layout_weight="1" 
      android:paddingTop="0dip" > 
      <TableRow 
       android:id="@+id/tableRow1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="top" 
       android:paddingTop="0dip" > 
       <TextView 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:ems="10" 
        android:gravity="left" 
        android:text="Namn" 
        android:textColor="#ababab" 
        android:textSize="25dip" /> 
      </TableRow> 
    </TableLayout> 
</LinearLayout> 

Trả lời

27

thay vì sử dụng

addFooterView(v) 

sử dụng

List.addFooterView(v, data, isSelectable); 

và thiết lập isselectable = false

List.addFooterView(v, null,false); 

nên footerView của bạn không còn có thể lựa chọn

+0

Bạn là người đàn ông cám ơn! =) – anders

+0

Bạn rất vui;) –

Các vấn đề liên quan