English 中文(简体)
最新清单
原标题:Android listview, current item counter

在我和海底应用中,我有一个清单,根据用户查询显示动态数据。

问题在于,我需要在行车上展示,目前用户已经选择了该项目(同时通过一览表进行计算)。

I Implemented OnItemSelectedListener and can catch the scrolling position. I initially defined a global variable and asigned it to -1.

int selectedRowIndex = -1;

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,long arg3) {

    selectedRowIndex = arg2;    
    footer.setText(String.valueOf(selectedRowIndex+1)+ " of " + String.valueOf(companyList.size()));
}

问题在于,当网页最初装满时,甚至还没有选定项目时,所选的RowIndex数值就变成了0(清单中的第一个项目)。 我可以理解为什么会发生这种情况,任何人都能够建议如何执行。

感谢

Edits

<RelativeLayout android:id="@+id/relativeLayout1" android:layout_height="wrap_content" android:layout_width="match_parent">

             <TextView android:text="TextView" 
                  android:id="@+id/noCompanysFound_Message" 
                  android:layout_width="wrap_content" 
                  android:layout_height="wrap_content"
                  android:visibility="gone"
                  android:textStyle="italic"
                  android:layout_marginTop="10dp">
                  </TextView>

            <ListView android:layout_width="match_parent"    
                      android:layout_height="match_parent" 
                      android:id="@+id/companylistView"
                      android:listSelector="@drawable/item_focus_bkg"
                      android:layout_above="@+id/footer_linearLayout"
                      android:focusable="false">
                      </ListView>                         

             <LinearLayout android:id="@+id/footer_linearLayout" android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="vertical" android:layout_alignParentBottom="true" android:background="@drawable/bottom_bkg" android:gravity="center_horizontal">         
                <TextView android:text="Footer Text" 
                          android:id="@+id/companylistFooterTextView" 
                          android:layout_width="wrap_content" 
                          android:layout_height="wrap_content" 
                          android:textColor="#FFFFFF">
                          </TextView>       
            </LinearLayout>        


        </RelativeLayout> 
问题回答

我认为,如果你的活动创立了<条码>,名单见焦点<>/代码>,<条码>第一行将选定,为什么<条码>清单中选取的<<>条/条码>,在代码中,名单第一行的索引将肯定被点名列一遍。

selectedRowIndex = arg2; became selectedRowIndex = 0;  

如果我错了,那么我就会提出建议或让我知道。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签