package com.hanqi.zuoyee; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.EditText; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; import java.util.List; public class jm extends AppCompatActivity { ListView listView; List<nei> list=new ArrayList<>(); final base bb=new base(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.jmm); listView=(ListView)findViewById(R.id.lv); list.add(new nei(R.drawable.a,"怪物","这就是怪物")); list.add(new nei(R.drawable.a,"怪物2","这就是怪物2")); list.add(new nei(R.drawable.a,"怪物3","这就是怪物3")); list.add(new nei(R.drawable.a,"怪物4","这就是怪物4")); list.add(new nei(R.drawable.a,"怪物5","这就是怪物5")); list.add(new nei(R.drawable.a,"怪物6","这就是怪物6")); list.add(new nei(R.drawable.a,"怪物7","这就是怪物7")); list.add(new nei(R.drawable.a,"怪物8","这就是怪物8")); list.add(new nei(R.drawable.a,"怪物9","这就是怪物9")); list.add(new nei(R.drawable.a,"怪物0","这就是怪物0")); listView.setAdapter(bb); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { list.remove(position); bb.notifyDataSetChanged(); Toast.makeText(jm.this, "已经删除", Toast.LENGTH_SHORT).show(); return true; } }); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final nei nn=list.get(position); final View v = View.inflate(jm.this,R.layout.jmmss,null); AlertDialog al=new AlertDialog.Builder(jm.this) .setView(v) .setTitle("输入要修改的内容") .setPositiveButton("确定",new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { EditText editText=(EditText)v.findViewById(R.id.et1); EditText editText2=(EditText)v.findViewById(R.id.et2); String t1=editText.getText().toString(); String t2=editText2.getText().toString(); if(t1.trim().length()!=0&&t2.trim().length()!=0){ nn.setText1(t1); nn.setText2(t2); bb.notifyDataSetChanged();} else { Toast.makeText(jm.this, "请正确输入", Toast.LENGTH_SHORT).show(); return; } } }) .setCancelable(true) .setNegativeButton("取消", null) .show(); } }); } class nei{ private int img; private String text1; private String text2; public int getImg() { return img; } public void setImg(int img) { this.img = img; } public String getText1() { return text1; } public void setText1(String text1) { this.text1 = text1; } public String getText2() { return text2; } public void setText2(String text2) { this.text2 = text2; } public nei(int img,String text1,String text2){ this.img=img; this.text1=text1; this.text2=text2; } } class base extends BaseAdapter{ @Override public int getCount() { return list.size(); } @Override public Object getItem(int position) { return list.get(position); } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { nei n=list.get(position); if(convertView==null){ convertView=View.inflate(jm.this,R.layout.jmms,null); } ImageView imageView=(ImageView)convertView.findViewById(R.id.iv); TextView textView=(TextView)convertView.findViewById(R.id.tv1); TextView textView2=(TextView)convertView.findViewById(R.id.tv2); imageView.setImageResource(n.getImg()); textView.setText(n.getText1()); textView2.setText(n.getText2()); return convertView; } } int ii=1; public void bb1(View v){ final View vi=View.inflate(jm.this,R.layout.jmsss,null); AlertDialog aa=new AlertDialog.Builder(jm.this) .setTitle("输入内容") .setPositiveButton("保存", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { EditText e=(EditText)vi.findViewById(R.id.et1); EditText e2=(EditText)vi.findViewById(R.id.et2); final ImageView iv=(ImageView)vi.findViewById(R.id.iv1); final ImageView iv2=(ImageView)vi.findViewById(R.id.iv2); final ImageView iv3=(ImageView)vi.findViewById(R.id.iv3); String s=e.getText().toString(); String s2=e2.getText().toString(); if(ii!=1&&s.trim().length()!=0&&s2.trim().length()!=0){ list.add(new nei(ii,s,s2)); bb.notifyDataSetChanged(); } else { Toast.makeText(jm.this, "请正确输入", Toast.LENGTH_SHORT).show(); } } }) .setNegativeButton("取消",null) .setCancelable(true) .setView(vi) .show(); } public void o(View v){ ii=R.drawable.a; Toast.makeText(jm.this, "图一", Toast.LENGTH_SHORT).show(); } public void oo(View v){ ii=R.drawable.aa; Toast.makeText(jm.this, "图2", Toast.LENGTH_SHORT).show(); } public void ooo(View v){ ii=R.drawable.aaa; Toast.makeText(jm.this, "图3", Toast.LENGTH_SHORT).show(); } }
时间: 2024-11-05 12:21:25