其他分享
首页 > 其他分享> > android-Twitter listViwe Fabric Kit的OClickItem

android-Twitter listViwe Fabric Kit的OClickItem

作者:互联网

我正在使用Twitter的Fabric工具包到我的android应用程序,并且我具有tweets的列表视图,但是当我尝试单击tweet(项目)以打开新活动(显示tweet的详细信息)时,但是当我单击对该项目,应用选择器会自动出现
似乎twitter-api已经设置了onItemClickListener,所以我问是否有人已经使用Fabric工具包,我需要帮助

ListView tweetLV = (ListView) root.findViewById(R.id.list_tweets);
adapter = new TweetViewAdapter<CompactTweetView>(getActivity());
tweetLV.setAdapter(adapter);

tweetLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        String hashtag = adapter.getItem(i);
        Intent intent = new Intent(getActivity(), DetailActivity.class)
            .putExtra(Intent.EXTRA_TEXT, hashtag);
        startActivity(intent);
    }
}); 

解决方法:

正如我在this question上建议的那样,您可以尝试创建一个自定义适配器,该自定义适配器将覆盖tweet的默认onClick行为:

class CustomTweetTimelineListAdapter extends TweetTimelineListAdapter {

    public CustomTweetTimelineListAdapter(Context context, Timeline<Tweet> timeline) {
        super(context, timeline);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view = super.getView(position, convertView, parent);

        //disable subviews to avoid links are clickable
        if(view instanceof ViewGroup){
            disableViewAndSubViews((ViewGroup) view);
        }

        //enable root view and attach custom listener
        view.setEnabled(true);            
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //TODO: implement your custom behavior when clicks
            }
        });
        return view;
    }

    // see full example to find helper method disableViewAndSubViews

}

完整代码示例here

希望能帮助到你.

标签:twitter-fabric,android
来源: https://codeday.me/bug/20191120/2047610.html