0
我是非常新的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項(與包含第二列表視圖):
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);
}
}
});
}
}
第一件事,如果您是'Android'的新手,則習慣使用'recyclerView'。 – Wizard
在適配器中是否有任何ImageButton或Button? –
單擊ListView項目時啓動相同的活動。那麼爲什麼使用if-else? –