在我的应用程序中,我有一个包含不同项目的 ListView。我遇到的问题是我想对每个特定项目执行侦听器或操作。现在,当您按下一个项目时,我拥有的代码会将其应用于所有项目,而不是专门应用于一个项目。
我想做的是在按下特定项目时流式传输视频。
这是我的代码:
public class MainActivity extends Activity {
private ListView listView1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ViedoStream viedoStream_data[] = new ViedoStream[]
{
new ViedoStream(R.drawable.image0, "Mission TV"),
new ViedoStream(R.drawable.image1, "HCBN Philippines"),
new ViedoStream(R.drawable.image2, "Global Family Network"),
new ViedoStream(R.drawable.image3, "2CBN"),
new ViedoStream(R.drawable.image4, "Red ADvenir"),
new ViedoStream(R.drawable.image5, "Alfa Television"),
new ViedoStream(R.drawable.image6, "Light Channel Hungary"),
new ViedoStream(R.drawable.image7, "Light Channel Rumania"),
new ViedoStream(R.drawable.image8, "Light Channel Germany"),
new ViedoStream(R.drawable.image9, "Terceiro Anjo"),
new ViedoStream(R.drawable.image10, "HCBN Indonesia"),
new ViedoStream(R.drawable.image11, "TV Famille")
};
ViedoStreamAdapter adapter = new ViedoStreamAdapter(this,
R.layout.listview_item_row, viedoStream_data);
listView1 = (ListView)findViewById(R.id.listView1);
View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
listView1.addHeaderView(header);
listView1.setAdapter(adapter);
listView1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView <?> parentAdapter, View view, int position,
long id) {
// Place code here with the action: RIGHT NOW I HAVE A TOAST FOR EXAMPLE ONLY
Toast.makeText(getApplicationContext(), "TV Selected", Toast.LENGTH_SHORT).show();
}
});
}}
如您所见,当一个项目被选中时,toast 将应用于 ListView 上的每个项目。请注意 Toast 只是我使用的一个例子。我想流式传输 http 视频。现在,我怎样才能做到这一点,以便每次我选择一个项目时,它只对该特定项目执行一个操作?
我为 iPhone 编程,我对这一切都不熟悉……在 iPhone 中,我就是这样做的。*这只是逻辑的示例:
if (item == @"TV Item" {
//Do Action
}
谢谢