的Android工作室清單活動名稱亮點爲紅色的Android工作室清單活動名稱紅色下劃線
MainActivity.Java
public class MainActivity extends Activity {
ListView list;
String[] web = {
"Finans",
"Sınav",
"Eğitim"
};
Integer[] imageId = {
R.drawable.home,
R.drawable.home,
R.drawable.home
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CustomList adapter = new CustomList(MainActivity.this, web, imageId);
list = (ListView) findViewById(R.id.list);
list.setAdapter(adapter);
}
}
CustomList.Java
public class CustomList extends ArrayAdapter<String> {
private final Activity context;
private final String[] web;
private final Integer[] imageId;
public CustomList(Activity context,
String[] web, Integer[] imageId) {
super(context, R.layout.activity_main, web);
this.context = context;
this.web = web;
this.imageId = imageId;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.activity_main, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.txt);
ImageView imageView = (ImageView) rowView.findViewById(R.id.img);
txtTitle.setText(web[position]);
imageView.setImageResource(imageId[position]);
return rowView;
}
}
活動名稱在清單文件中顯示爲紅色下劃線。當我編譯&在手機上運行它在手機上崩潰Android工作室不顯示我的錯誤。這種表現有什麼問題,我無法理解。
我認爲你的活動包不同於logcat中顯示的錯誤 –
顯示包結構 –
你的MainActivity在哪個包? –