У меня есть пустые массивы(workernamem,solarym,occupationm).С первого активити я ввожу параметры,которые хочу сохранить в EditText,получаю их и упаковываю в файл настроек.
Второй активити должен представлять собой список с выводом имени,зарплаты и профессии сотрудника,но я не знаю каким методом можно заполнить массив,имея файл настроек!
Заранее спасибо!
Вот полный код:
firstclass
Код: Выделить всё
package com.develope.vladimir.myapplication;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
/**
* Created by Vladimir on 30.10.2015.
*/
public class firstclass extends Activity {
EditText eTsolary,eTOc,eTName;
Button btnUpd, btnGo;
SharedPreferences sPref;
final String NAME = "name";
final String Occupation="occupation";
final String Solary="solary";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.firstactivity);
eTsolary=(EditText)findViewById(R.id.eTsolary);
eTOc=(EditText)findViewById(R.id.eToc);
eTName=(EditText)findViewById(R.id.eTname);
btnUpd=(Button)findViewById(R.id.buttonUpDB);
btnGo=(Button)findViewById(R.id.btnGO);
}
public void updateDB(View view){
sPref=getPreferences(MODE_PRIVATE);
SharedPreferences.Editor ed=sPref.edit();
ed.putString(NAME,eTName.getText().toString());
ed.putString(Occupation,eTOc.getText().toString());
ed.putString(Solary,eTsolary.getText().toString());
ed.commit();
Toast.makeText(this,"База обновлена!",Toast.LENGTH_SHORT).show();
}
public void GoActivity(View view){
Intent go=new Intent(this,MainActivity.class);
startActivity(go);
}
}
Код: Выделить всё
package com.develope.vladimir.myapplication;
import android.app.Activity;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends Activity {
String[] workernamem = {};
int[] solarym = {};
String[] occupationm = {};
int[] colors = new int[2];
SharedPreferences sPref;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
colors[0]=Color.parseColor("#471515");
colors[1]=Color.parseColor("#E8ECF3");
LinearLayout linLayout=(LinearLayout) findViewById(R.id.linLayout);
LayoutInflater Itlnflater=getLayoutInflater();
for (int i = 0;i < workernamem.length;i++){
View item = Itlnflater.inflate(R.layout.items, linLayout, false);
TextView tvName=(TextView)item.findViewById(R.id.tvName);
tvName.setText(workernamem[i]);
tvName.setTextColor(getResources().getColor(R.color.Orange));
TextView tvSolary=(TextView)item.findViewById(R.id.tvOc);
tvSolary.setText(occupationm[i]);
tvSolary.setTextColor(getResources().getColor(R.color.Green));
TextView tvOc=(TextView)item.findViewById(R.id.tvSolary);
tvOc.setText(String.valueOf(solarym[i]));
item.getLayoutParams().width=ViewGroup.LayoutParams.MATCH_PARENT;
item.setBackgroundColor(colors[0]);
item.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
linLayout.setBackgroundColor(colors[i%2]);
linLayout.addView(item);
}
}
}