我在ListView
中有Fragment
,我需要能够检测到ListView中的某个项目何时被选中。我需要列表项来沿这些行抛出一个标记或类似的内容,以便包含Fragments的Main Activity中的方法可以检测ListView是否被操作。我需要主活动中的方法基本上像这样:
public void doSomething(){
if(Fragment ListView onItemClick is detected){
//--- do something
} else {
//--- don't do anything
}
}
片段ListView中的OnItemClickListener
需要表明它已被采取行动,如下所示:
list_LV.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cursor getPathCursor = (Cursor) list_LV.getItemAtPosition(position);
String cursorSDFStr = getPathCursor.getString(getPathCursor.getColumnIndexOrThrow("sdfdate"));
String cursorCalDateStr = getPathCursor.getString(getPathCursor.getColumnIndexOrThrow("caldate"));
String cursorURLStr = getPathCursor.getString(getPathCursor.getColumnIndexOrThrow("path"));
String cursorTitleStr = getPathCursor.getString(getPathCursor.getColumnIndexOrThrow("title"));
String cursorbodyStr = getPathCursor.getString(getPathCursor.getColumnIndexOrThrow("body"));
Intent slpI = new Intent("com.myapp.LISTVIDEO");
slpI.putExtra("SDFKey", cursorSDFStr);
slpI.putExtra("CalDateKey", cursorCalDateStr);
slpI.putExtra("PathKey", cursorURLStr);
slpI.putExtra("TitleKey", cursorTitleStr);
slpI.putExtra("bodyKey", cursorbodyStr);
startActivity(slpI);
}
});
答案 0 :(得分:1)
您应该按照此处列出的步骤http://developer.android.com/guide/components/fragments.html#CommunicatingWithActivity
进行操作您可以使用广播或类似Otto http://square.github.io/otto/
之类的广告