Androidの簡単な設定ページでパラメータを保存します.
ここのSUは簡単なxmlヘルプ類です.コードを入れないのは簡単です.
, , EditText , , 。
/**
*
* 1. ?
* 。
* 2. , ?
* , ListView , :
* findViewById, UI ; ListView
* BaseAdapter , , 。
*/
public class setActivity extends Activity {
// , ,
private SU su;//SU , 。
private List mlist;// , ArrayList
private String[] values,names;// String , ,
private ListView listView;//
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.set);
//
su=new SU(getApplicationContext());
//
values=new String[]{" 1, 2"};
listView=findViewById(R.id.list);
names=new String[]{" 1, 2"};
mlist=new ArrayList<>();
// , ,
// , ,
if(su.get("0").equals("NO")){
//for ,
for(int i=0;i adapterView, View view, int i, long l) {
al(i);
}
});
}
public void re(){
// , list ,
mlist.clear();
for(int i=0;i list;
public MyBaseAdapter(List liste){
list=liste;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int i) {
return list.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
// , ViewHolder ,
// LayoutInflater
ViewHolder viewHolder;
if(view==null){
viewHolder=new ViewHolder();
view= LayoutInflater.from(getApplicationContext()).inflate(R.layout.item,null);
viewHolder.name=view.findViewById(R.id.name);
viewHolder.value=view.findViewById(R.id.value);
view.setTag(viewHolder);
}else {
// , ,findViewByID
// view.getTag
viewHolder= (ViewHolder) view.getTag();
}
Data data =list.get(i);
viewHolder.value.setText(data.value);
viewHolder.name.setText(data.name);
return view;
}
class ViewHolder{
TextView name,value;
}
}
class Data{
String name,value;
public Data(String name, String value) {
this.name = name;
this.value = value;
}
}
public void al(final int num){
/**
* : builder, , dissmiss , create AlertDialog
*/
AlertDialog.Builder builder=new AlertDialog.Builder(setActivity.this);
View view =LayoutInflater.from(getApplicationContext()).inflate(R.layout.dig,null);
final EditText editText =view.findViewById(R.id.editText);
builder.setPositiveButton(" ", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// item ,
values[num]=editText.getText().toString();
// adapter
re();
}
});
builder.setView(view);
builder.show();
}
public void set(View view){
for(int i=0;i