我要做的是隐藏listview上的下一个项目,当我们点击上一个项目时,将出现下一个隐藏项目:
示例:单击A(列表视图上的项目),Apple(列表视图中隐藏的下一项)将随声音一起显示。 (例如:Apple)
[]
我的活动代码:
public class SecondActivity extends AppCompatActivity {
ArrayAdapter<String> adapter;
ListView GrelistView;
String[] greetings = {"A",
"Apple",
"B",
"Ball"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
GrelistView = (ListView) findViewById(R.id.GrelistView);
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, greetings);
GrelistView.setAdapter(adapter);
GrelistView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getBaseContext(), parent.getItemAtPosition(position) + "is selected", Toast.LENGTH_LONG).show();
}
});
}
答案 0 :(得分:0)
我认为@ Chirag.T是对的,您正在寻找的是ExpendableListView,其中将显示子类别的向下箭头,当您单击该向下箭头时,您的子类别将显示。 请参阅以下链接 - https://developer.android.com/reference/android/widget/ExpandableListView.html