我喜欢在长按一下时分享项目,我使用onItemClick
转到另一个意图并使用onItemLongClick
进行分享但onItemLongClick
无效请帮助我
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
ViewHolder ocHolder = (ViewHolder)view.getTag();
TextView ocTextID =(TextView)ocHolder.txtID;
TextView ocTextDsc =(TextView)ocHolder.txtDsc;
Intent intents = new Intent(Intent.ACTION_SEND);
intents.setType("text/plain");
String my_string = ocTextTitle.getText().toString();
intents.putExtra(Intent.EXTRA_TEXT, my_string);
startActivity(Intent.createChooser(intents, "Share this text via"));
return false;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
ViewHolder ocHolder = (ViewHolder)view.getTag();
TextView ocTextID =(TextView)ocHolder.txtID;
TextView ocTextTitle =(TextView)ocHolder.txtTitle;
Intent i = new Intent(hozeactivity.this, ChildList.class);
i.putExtra("pId", ocTextID.getText().toString() );
i.putExtra("uName", ocUser );
i.putExtra("pass", ocPass);
i.putExtra("isOnline", isOnline);
startActivity(i);
}
答案 0 :(得分:0)
将return false;
更改为return true;
,告诉您正在处理该事件的视图。修改您的代码如下:
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
ViewHolder ocHolder = (ViewHolder)view.getTag();
TextView ocTextID =(TextView)ocHolder.txtID;
TextView ocTextDsc =(TextView)ocHolder.txtDsc;
Intent intents = new Intent(Intent.ACTION_SEND);
intents.setType("text/plain");
String my_string = ocTextTitle.getText().toString();
intents.putExtra(Intent.EXTRA_TEXT, my_string);
startActivity(Intent.createChooser(intents, "Share this text via"));
return true;
}
还要确保ListView注册setOnItemLongClickListener():
myListView.setOnItemLongClickListener(listener);