[英]Issues In Intent Passing Using Database
My problem is how to pass Rating bar value in to another activity using another putExtra method?any one solve this problem? 我的问题是如何使用另一个putExtra方法将评级栏值传递给另一个活动?任何一个解决这个问题? Here is my First activity
这是我的第一项活动
public void giveRating(View v)
{
String Name = spinner.getSelectedItem().toString();
Float Rating = ratingBar.getRating();
String query = "insert into Rating values('"+Name+"',"+Rating+")";
try
{
sqLiteDatabase.execSQL(query);
AlertDialog.Builder ab = new AlertDialog.Builder(this);
ab.setMessage("DATA SAVED");
ab.show();
}catch (Exception e)
{
Log.e("InsertionException",""+e);
}
}
public void viewRating(View v)
{
try {
StringBuffer sb = new StringBuffer();
String query = "select * from Rating";
Cursor cursor = sqLiteDatabase.rawQuery(query, null);
boolean res = cursor.moveToFirst();
if (res) {
do {
String Name = cursor.getString(0);
String Rating = cursor.getString(1);
sb.append(Name + ":" + Rating+"\n");
} while (cursor.moveToNext());
} else {
AlertDialog.Builder ab = new AlertDialog.Builder(this);
ab.setMessage("No data To read");
ab.show();
}
String value = sb.toString();
Intent i = new Intent(MainActivity.this, Items.class);
i.putExtra("k1", value);
startActivity(i);
}
catch (Exception e)
{
Log.e("ReadDataEXception",""+e);
}
Second Activity 第二项活动
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.items_layout);
textView = (TextView)findViewById(R.id.tv3);
textView1 = (TextView)findViewById(R.id.tv4);
Intent i = getIntent();
String name;
Bundle b = getIntent().getExtras();
name= b.getString("k1");
textView.setText(name);
textView.setTextSize(20);
Database Activity 数据库活动
public Database(Context c)
{
super(c,DBNAME,null,VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
try {
String query = "create table Rating(Name TEXT,Rating REAL)";
db.execSQL(query);
}catch (Exception e)
{
Log.e("TableCreationException",""+e);
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
You could simply add another putExtra
with keyName
like 您可以简单地添加另一个带有
keyName
putExtra
Intent i = new Intent(MainActivity.this, Items.class);
i.putExtra("name", name);
i.putExtra("rating",rating);
startActivity(i);
And get from Items activity 从Items活动中获取
Intent i = getIntent();
String name;
String rating;
Bundle b = getIntent().getExtras();
name= b.getString("name");
rating= b.getString("rating");
textView.setText(name);
textView1.setText(rating);
textView.setTextSize(20);
Hope it is helpful for you. 希望它对你有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.