我正在尝试构建列表视图,并且列表视图中的每个项目都会打开其特定的新活动。但我收到一些字符串转换错误。请帮忙。我收到此错误:
Type mismatch: cannot convert from java.lang.String to com.example.cprograms.String Array.java
这是我的java文件:
package com.example.cprograms;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Ctypes extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ctypes);
String[] types = new String[] {"Arrays", "Strings" };
setListAdapter(new ArrayAdapter<String>(this,R.layout.ctypes, types));
ListView list = getListView();
list.setTextFilterEnabled(true);
list.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View v, int position,
long arg3) {
switch(position)
{
case 0: Intent newActivity = new Intent(v.getContext(), Array.class);
startActivity(newActivity);
break;
case 1: Intent newActivity1 = new Intent(v.getContext(), String.class);
startActivity(newActivity1);
break;
}
}
});
}
}
这是我的 xml 布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Ctypes" >
<ListView
android:id="@+id/list_ctypes"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >"
</ListView>