各位大家好 小的第一次接觸android studio
希望大家能告訴小的究竟何處出了問題導致執行可以
但listview卻沒有顯示任何東西!
package tw.edu.tut.mis.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class MainActivity extends AppCompatActivity {
//ArrayAdapter<String> mAdapter;
ListView mLv;
ArrayList<String> mlist;
public mysql DH = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent add =this.getIntent();
//mlist=add.getStringArrayListExtra("lll");
mlist =add.getStringArrayListExtra("lll");
mLv=findViewById(R.id.listview);
List<HashMap<String , String>> list = new ArrayList<>();
ListView mLv=(ListView)findViewById(R.id.listview);
ListAdapter listAdapter = new SimpleAdapter(
this,
list,
android.R.layout.simple_list_item_2 ,
new String[]{"title" , "text"} ,
new int[]{android.R.id.text1 , android.R.id.text2});
mLv.setAdapter(listAdapter);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent it = new Intent(MainActivity.this,Main2Activity.class);
startActivity(it);
}
});
}
}
package tw.edu.tut.mis.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Main2Activity extends AppCompatActivity {
// ArrayAdapter<String> mAdapter;
ArrayList<String> mlist;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
final List<HashMap<String,String>> list=new ArrayList<>();
Button bt6;
bt6 = findViewById(R.id.button6);
findViewById(R.id.button6).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText ed1;
ed1=findViewById(R.id.editText);
String s;
s=ed1.getText().toString();
EditText ed2;
ed2=findViewById(R.id.editText2);
String x ;
x=ed2.getText().toString();
String[] title = new String[]{s};
String[] text = new String[]{x};
HashMap<String,String> hashMap=new HashMap<>();
hashMap.put("title",s);
hashMap.put("text",x);
list.add(hashMap);
Intent it = new Intent(Main2Activity.this, MainActivity.class);
it.putStringArrayListExtra("lll", mlist);
startActivity(it);
}
});
https://ithelp.ithome.com.tw/upload/images/20201019/20131900A1U1GSqweT.jpg