如何使用Android的共享preference来存储动态表中的值 [英] How to Store dynamic table value using SharedPreference in android
本文介绍了如何使用Android的共享preference来存储动态表中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发基于Android的应用程序下我提到我的应用程序输出的Web服务....
这里是我的动态表视图
I am developing web services based android application below i mentioned my application output.... here's my dynamic table view
final LinearLayout linear = new LinearLayout(
MainActivity.this);
MainLayout.setWeightSum(1.0f);
TableRow row1 = new TableRow(MainActivity.this);
row1.setId(1000 + sCount);
text1 = new TextView(MainActivity.this);
text1.setText(button.getText());
text1.setTextColor(Color.WHITE);
LayoutParams params = new TableRow.LayoutParams(0,
LayoutParams.WRAP_CONTENT, 2f);
text1.setLayoutParams(params);
// text1.setGravity(100);
final Button button = new Button(MainActivity.this);
EditText e = new EditText(MainActivity.this);
LayoutParams params1 = new TableRow.LayoutParams(0,
LayoutParams.WRAP_CONTENT, 0.5f);
e.setLayoutParams(params1);
e.setInputType(InputType.TYPE_CLASS_NUMBER);
arryList.add(text1.getText().toString());
nameArray = arryList.toArray(new String[arryList
.size()]);
String itemname = text1.getText().toString();
button.setText(" X ");
button.setId(2000 + sCount);
LayoutParams params2 = new TableRow.LayoutParams(0,
LayoutParams.WRAP_CONTENT, 0.5f);
button.setLayoutParams(params2);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MainLayout.removeView(findViewById(v
.getId() - 1000));
}
});
sCount++;
row1.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.FILL_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
row1.setGravity(Gravity.CENTER_VERTICAL);
row1.setPadding(1, 1, 1, 1);
row1.addView(text1);
row1.addView(e);
row1.addView(button);
MainLayout.addView(row1);
}
ll.addView(MainLayout);
// TODO Auto-generated method stub
输出
我想TextView的价值观和的EditText值存储在共享preference ......从那以后,我要检索相同的值,并加载相同的表格布局...我怎么能做到这一点?
请任何帮助我...在此先感谢..
i want store the textview values and edittext values in sharedpreference...after that i want to retrieve the same value and load the same table layout...how can i do that?? please any help me...thanks in advance..
推荐答案
要保存
SharedPreferences myPrefs = this.getSharedPreferences("myPrefs", MODE_PRIVATE);
SharedPreferences.Editor prefsEditor = myPrefs.edit();
prefsEditor.putInt("VariableName", Value);
prefsEditor.putInt("VariableName2", Value);
prefsEditor.commit();
要读
SharedPreferences myPrefs = this.getSharedPreferences("myPrefs", MODE_PRIVATE);
int d = myprefs.getInt("VariableName", defaultvalue);
这篇关于如何使用Android的共享preference来存储动态表中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文