因此,仅此而已,这是我的代码,当我尝试使用Edittext和用于将数据保存到listView的按钮时,它可以正常工作,并且所有项目都显示在列表视图中,但是看起来像在下面,它仅显示一个...
public class History extends Activity {
ListView show;
Button Home, toMap, Next;
EditText listTextMaker;
ArrayList<String> addArray = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
Home = findViewById(R.id.homeBtn);
toMap = findViewById(R.id.backBtn);
Next = findViewById(R.id.nextBtn);
show = findViewById(R.id.textHistory);
listTextMaker = findViewById(R.id.text);
listTextMaker.setVisibility(View.INVISIBLE);
ConstructorBuilder();
}
public void Constructor(){
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String dataHistory = prefs.getString("History", null );
addArray.add(dataHistory);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(History.this, android.R.layout.simple_expandable_list_item_1, addArray);
show.setAdapter(adapter);
}
public void ConstructorBuilder(){
Constractor();
}
}
答案 0 :(得分:0)
您仅在列表中添加一个数据:
String dataHistory = prefs.getString("History", null );
addArray.add(dataHistory);
如果您需要多个数据,则只需使用以下代码:
String dataHistory = prefs.getString("History", null );
addArray.add(dataHistory);
addArray.add(dataHistory);
addArray.add(dataHistory);
addArray.add(dataHistory);
addArray.add(dataHistory);