2013-03-08 27 views
-1

使用SharedPreference我开发基于Android的应用程序下我提到我的应用程序输出的Web服务动态表值.... 这里是我的动态表视图如何存储在Android的

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 

输出

enter image description here

我想将textview值和edittext值存储在sharedpreference ...之后,我想检索相同的值并加载相同的表格布局...我该怎么做? 请任何帮助我...在此先感谢..

+0

我用SavePreferences( “MEM1”,text1.getText()。的toString( ));用于存储text1的值....但它只显示最后输入的值..我可以解决它....我想显示所有text1值.... – 2013-03-08 06:07:33

回答

1

为了节省

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); 
+0

我用SavePreferences(“MEM1”,text1.getText ()的ToString());用于存储text1的值....但它只显示最后输入的值..如何解决它....我想显示所有text1值.... – 2013-03-08 06:04:34

+0

把这个“保存”的代码,其中价值正在改变在运行时或动态,以便最新的值将在共享的pref – DjHacktorReborn 2013-03-08 06:08:19