Android的/的ListView:选择loading DATAS后第一项 [英] Android/ListView : Select first item after loading datas
问题描述
修改
我必须告诉你,我的ListView是由AsyncTask的填充。
EDIT I must tell you that my ListView is populate by an AsyncTask.
当我在onPostExecute方法做的code以下正常工作:
The code below works fine when I do in onPostExecute method :
synchronized (mListView) {
if(mFeeds==null || mFeeds.size()==0){
Utils.Log("mFeeds empty");
_this.setListShown(false);
}else{
Utils.Log("mFeeds Full");
_this.setListShown(true);
mListView.setAdapter(new ListFeedsAdapter(mActivity,mFeeds));
mListView.notifyAll();
NewsFeedsDetailViewPagerFragment fragment = (NewsFeedsDetailViewPagerFragment) getFragmentManager()
.findFragmentById(R.id.feeddetailViewPagerFragment);
if(fragment!=null){
mListView.performItemClick(null, 0, mListView.getFirstVisiblePosition());
}
}
}
该项目被点击,我的详细视图是填充...
The item is clicked and my detail view is populate...
我尝试我的片段改变改变了ListFragment但没有...
I try to change my Fragment to a ListFragment but nothing changed...
编辑结束
有关我的应用程序,我在屏幕左侧的ListView并在合适的一个细节视图中创建(平板)的用户界面。
我想自动选择负载DATAS后的第一个项目,并查看详细信息。
For my application, I created an UI (for tablet) with ListView at left screen and a detail view at the right. I would like to automatically select the first item after loading datas, and view the detail.
我能够通过调用做到这一点 mListView.performItemClick(NULL,0,mListView.getFirstVisiblePosition());
和
I am able to do this by calling mListView.performItemClick(null, 0, mListView.getFirstVisiblePosition());
and
mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
NewsFeedsDetailViewPagerFragment fragment = (NewsFeedsDetailViewPagerFragment)
getFragmentManager().findFragmentById(R.id.feeddetailViewPagerFragment);
if(fragment!=null){
fragment.setFeedDetail(mFeeds, arg2);
}
});
现在,我想要做的就是要突出Gmail等应用程序的平板电脑中的第一项。
我用一个选择的背景上的每一行,如:
Now, what I want to do is to highlight the first item like Gmail application for tablet. I use a selector background on each row like :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/selected_item_background" android:state_activated="true"/>
<item android:drawable="@drawable/pressed_item_background" android:state_activated="false" android:state_pressed="true"/>
<item android:drawable="@drawable/pressed_item_background" android:state_focused="true"/>
<item android:drawable="@drawable/unselected_item_background"/>
</selector>
当我使用 mListView.getChildAt(ARG2).setActivated(真);
在onItemClick监听器,我有一个NullPointerException异常,因为 mListView.getChildAt (ARG2)
为空,只有当我把perforItemClick。如果我只是注释此行,然后单击某行,此行的亮点是在Gmail应用程序。
When I use mListView.getChildAt(arg2).setActivated(true);
in the onItemClick listener, I have a NullPointerException because mListView.getChildAt(arg2)
is null, only if I keep the perforItemClick. If I just comment this line, and click on a row, this row is highlight as in Gmail application.
您可以帮我,告诉我什么,我做错了吗?
Can you help me and tell me what I'm doing wrong ?
感谢提前
推荐答案
我找到了解决我的问题,我张贴在这里解决,如果有一个开发商是在同样的情况。
I found a solution to my problem and I post here the solution if there is a developer that is in the same situation.
我创造了我的适配器方法,它标志至极位置必须被激活,并在我的getView方法,我只是当前位置比较标志并激活与否行:
I created a method in my adapter that flag wich position must be activated and in my getView method, I just compare the current position to the flag and activate or not the row :
((ListFeedsAdapter) mListView.getAdapter()).setItemSelected(mOldPosition);
和在适配器:
private int mItemSelected = -1 ;
public void setItemSelected(int position){
mItemSelected=position;
}
public View getView(int position, View convertView, ViewGroup parent){
//some code ....
if(mItemSelected==position){
convertView.setActivated(true);
}else{
convertView.setActivated(false);
}
}
感谢您!
这篇关于Android的/的ListView:选择loading DATAS后第一项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!