Android开发新手。
当我试图测试我的“历史”活动时,我遇到了这个问题
不知道该怎么做以及怎么做。
我搜索了一些答案,但它们都超出了我的范围,所以我必须发布我的答案
而且我也一直在logcat中得到这个错误:
“E / memtrack:无法加载memtrack模块”
不知道如何解决它
提前谢谢你们。
这是OnclickListener
findViewById(R.id.view_history_button).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
Intent toHistory=new Intent(main,history.class);
main.startActivity(toHistory);
}
} );
这是“历史”活动的代码
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class history extends AppCompatActivity {
public ListView listView = null;
private List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
private SimpleAdapter simpleAdapter = null;
private String date;
private String target;
private String item;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
listView=(ListView)findViewById(R.id.listview) ;
simpleAdapter= new SimpleAdapter(this,getdata() , R.layout.listview_content,
new String[] { "date","target","item"}, new int[] { R.id.time ,R.id.name,R.id.item});
listView.setAdapter(simpleAdapter);
}
private List<Map<String, Object>> getdata() {
DBHelper dbHelper = new DBHelper(getApplicationContext(),
"Delivery_info",null,1);
SQLiteDatabase db = dbHelper.getReadableDatabase();
Cursor cursor=db.rawQuery("select * from info_table",null);
if(cursor.moveToFirst() ){
while(!cursor.isAfterLast())
date = cursor.getString(cursor.getColumnIndex("date"));
target = cursor.getString(cursor.getColumnIndex("target"));
item = cursor.getString(cursor.getColumnIndex("item"));
Map<String, Object> map = new HashMap<String, Object>();
map.put("date", date);
map.put("target", target);
map.put("item", item);
list.add(map);
// }
}
return list;
}
}
这就是Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.robottracking">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".task" />
<activity android:name=".history" />
<activity android:name=".MainActivity"></activity>
</application>
</manifest>
这是logcat的截图 enter image description here