EDIT I must tell you that my ListView is populate by an AsyncTask.
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...
I try to change my Fragment to a ListFragment but nothing changed...
EDIT END
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.
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);
}
});
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>
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 ?
Thank in advance