2014-10-30 35 views
2

我需要有一個ListView Indexable,當我在一個數字click重定向到的index是相同的ListView Indexable的數量。例如當我在click上2時,它將我重定向到rowindexListView)的個數爲2。ListView可索引?

Image

+0

檢查:http://simpleandroidcoding.blogspot.in/2013/04/indexable-listview-tutorial-source-code.html – 2014-10-30 06:48:24

+0

沒有找到它的ListView基地第一個字符。我需要查找基礎(索引)的ListView。謝謝 – 2014-10-30 06:50:36

+0

你可以使用索引而不是字母表。 – 2014-10-30 06:51:52

回答

1

試試這種方式,希望這會幫助你解決你的問題。

如果您不想更改IndexScroller類中的任何代碼,請在您的SimpleAdapter類中更改以下代碼。

右側部分值列表中沒有項目。

private String[] mSections; 

public SimpleAdapter(ArrayList<String> mCurrentList, Context mContext) { 
    super(); 
    this.mCurrentList = mCurrentList; 
    mSections = new String[mCurrentList.size()]; 
    for(int i=0;i<mCurrentList.size();i++){ 
     mSections[i] = String.valueOf(i+1); 
    } 
    this.mContext = mContext; 
} 

嘗試給出所選右側部分值以移動列表。

@Override 
public int getPositionForSection(int section) { 
    return section; 
} 
+1

非常感謝。 ;) – 2014-10-30 08:56:55

+0

@ A.A,很高興幫助你.. – 2014-10-30 08:57:36

1

我看到IndexScroller.java項目在onTouchEvent評論這一行:

//mListView.setSelection(mIndexer.getPositionForSection(mCurrentSection)); 

然後加:

for (int i = 1; i < count; i++) { 
        if(mCurrentSection == i){ 
         mListView.setSelection(mCurrentSection); 
        } 
       } 

現在你可以工作。 ;) 這個例子是:

http://simpleandroidcoding.blogspot.in/2013/04/indexable-listview-tutorial-source-code.html 

有了,你應該將號碼添加到indexable然後找到Rows基地IDS Rows的差異。