package com.example.android.bloodapp4;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView ourList = findViewById(R.id.theList);
ArrayList<String> list = new ArrayList<>();
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(MainActivity.this , android.R.layout.simple_list_item_1,list);
list.add("Account");
list.add("Posts");
list.add("Donations you made");
ourList.setAdapter(arrayAdapter);
ourList.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent AccIntent = new Intent(MainActivity.this, AccountActivity.class);
startActivity(AccIntent);
}
});
}
}
答案 0 :(得分:0)
因为不是真正创建ArrayAdapter,所以必须以simple_list_item_1布局创建TextView,并且必须将其添加到ArrayAdapter构造函数中。假设textview2是您在simple_list_item_1中的textview。
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(MainActivity.this , android.R.layout.simple_list_item_1,textview2,list);
我相信那会起作用。
答案 1 :(得分:0)
您是否已在AndroidManifest.xml中声明了AccountActivity
?
一个简单的例子:
<application
....>
<activity
android:name=".AccountActivity"/>
</application>