我在android中非常新。我正在制作一个列表视图,每次我点击列表的项目时它会显示第二个列表视图,但第二个列表视图中的所有项目都不可点击。我已经尝试了所有解决方案,使第二个列表中的项目可以点击,但不适用于我。 到目前为止,这是我的代码:
主要活动:
public class MainActivity extends AppCompatActivity {
String[] boundryitems = {"Boundry Wall","Front Elevation","Corridor","Kitchen","Bedroom1"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Boundry List Adapter
final ArrayAdapter boundry_Item1 = new ArrayAdapter<String>(this,
R.layout.activity_main,R.id.texti, boundryitems);
ListView listView11 = (ListView) findViewById(R.id.listvi);
listView11.setAdapter(boundry_Item1);
listView11.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if (position == 0) {
Intent myIntent = new Intent(view.getContext(), item1.class);
startActivityForResult(myIntent, 0);
}
if (position == 1) {
Intent myIntent = new Intent(view.getContext(), item1.class);
startActivityForResult(myIntent, 0);
}
if (position == 2) {
Intent myIntent = new Intent(view.getContext(), item1.class);
startActivityForResult(myIntent, 0);
}
if (position == 3) {
Intent myIntent = new Intent(view.getContext(), item1.class);
startActivityForResult(myIntent, 0);
}
if (position == 4) {
Intent myIntent = new Intent(view.getContext(), item1.class);
startActivityForResult(myIntent, 0);
}
if (position == 5) {
Intent myIntent = new Intent(view.getContext(), item1.class);
startActivityForResult(myIntent, 0);
}
if (position == 6) {
Intent myIntent = new Intent(view.getContext(), item1.class);
startActivityForResult(myIntent, 0);
}
if (position == 7) {
Intent myIntent = new Intent(view.getContext(), item1.class);
startActivityForResult(myIntent, 0);
}
}
});
}
}
第1项(包含第二个Listview):
public class item1 extends Activity {
String[] snaglistciv = {"Paint","Garbage Room","Pump Room","Lights","Joint"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.snag_item);
//Snag List Adapter
final ArrayAdapter adapterSnag_Item = new ArrayAdapter<String>(this,
R.layout.snag_item,R.id.textsnag, snaglistciv);
final ListView listView = (ListView) findViewById(R.id.listsnag);
listView.setAdapter(adapterSnag_Item);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if (position == 0) {
Intent myIntent = new Intent(view.getContext(), camerapic.class);
startActivityForResult(myIntent, 0);
}
if (position == 1) {
Intent myIntent = new Intent(view.getContext(), camerapic.class);
startActivityForResult(myIntent, 0);
}
if (position == 2) {
Intent myIntent = new Intent(view.getContext(), camerapic.class);
startActivityForResult(myIntent, 0);
}
if (position == 3) {
Intent myIntent = new Intent(view.getContext(), camerapic.class);
startActivityForResult(myIntent, 0);
}
if (position == 4) {
Intent myIntent = new Intent(view.getContext(), camerapic.class);
startActivityForResult(myIntent, 0);
}
if (position == 5) {
Intent myIntent = new Intent(view.getContext(), item1.class);
startActivityForResult(myIntent, 0);
}
if (position == 6) {
Intent myIntent = new Intent(view.getContext(), item1.class);
startActivityForResult(myIntent, 0);
}
if (position == 7) {
Intent myIntent = new Intent(view.getContext(), item1.class);
startActivityForResult(myIntent, 0);
}
}
});
}
}
答案 0 :(得分:0)
您的活动的contentView和listview的项目视图是相同的??? R.layout.snag_item
setContentView(R.layout.snag_item);
final ArrayAdapter adapterSnag_Item = new ArrayAdapter<String>(this,
R.layout.snag_item,R.id.textsnag, snaglistciv);