我正在尝试制作一个带有2个列表视图的Android应用程序 - 主列表视图显示一般信息列表,在行选择后应显示第二个列表视图(带有详细信息)。 一般listview运行正常,但我有第二个listview的实现问题。 我尝试了什么:我复制了一般listview的代码并将其(变量,视图名称,...)更改为详细的listview,但是我收到了错误。 我的代码不是很短,所以我尝试粘贴重要的块。如果遗漏了什么,请告诉我。
一般listview适配器代码:
public class ListViewAdapter extends BaseAdapter {
Context context;
List<Czoznam> zoznam = new ArrayList<Czoznam>();
LayoutInflater inflater;
public ListViewAdapter(Context context, List<Czoznam> aZoznam ) {
this.context = context;
this.zoznam=aZoznam;
}
public View getView(int position, View convertView, ViewGroup parent) {
//TextView and variable definitions here
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.listview_item, parent, false);
//textview value assignments here...
return itemView;
}
mainactivity:
public class MainActivity extends AppCompatActivity {
ListView zoznamListView;
ListViewAdapter adapter;
List<Czoznam> zoznamList = new ArrayList<Czoznam>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview_main);
zoznamListView = (ListView) findViewById(R.id.zozn);
adapter = new ListViewAdapter(MainActivity.this, zoznamList);
zoznamListView.setAdapter(adapter);
zoznamListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
//it works, applications gets here
}
});
所以我复制了上面显示的代码(创建了ListViewDetailAdapter),更改了变量,创建了布局。并尝试这样做:
zoznam1ListView = (ListView) findViewById(R.id.zoznamSprav);
adapter1 = new ListViewDetailAdapter(this, zoznam1List);
zoznam1ListView.setAdapter(adapter1);
但我在第二行收到错误:adapter1 = new ...
error: incompatible types: ListViewDetailAdapter cannot be converted to ListViewAdapter
我检查了代码,我不认为我忘记在复制的部分中更改某些变量。我应该在哪里搜索错误? 谢谢你的帮助。