
사진과 같이 에디트텍스트에 1번 리스트를 클릭하게 되면 aaa/111 이들어가야하는데 ;
com.example...... 과 같은 패키지에 들어가는 내용이 출력되네요 ;
무엇이 문제인지 모르겠습니다 ㅜ .
public class MainActivity extends Activity implements View.OnClickListener,AdapterView.OnItemClickListener {
SQLiteDatabase myDB;
SimpleAdapter myADT;
ArrayList<String> aryMBRList;
ArrayAdapter<String> adtMembers;
ListView lstView;
ArrayList<AdepterDTO> arr_list = null;
DBHandler dbHandler;
Button btnInsert, btnUpdate, btnSerch, btnDelete,btnSelect;
EditText edtid,edtCarName, edtCarPower;
Cursor cursor = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtid =(EditText)findViewById(R.id.editid);
edtCarName = (EditText) findViewById(R.id.editText);
edtCarPower = (EditText) findViewById(R.id.editText2);
btnInsert = (Button) findViewById(R.id.btnInsert);
btnUpdate = (Button) findViewById(R.id.btnupdate);
btnDelete = (Button) findViewById(R.id.btnDelete);
btnSerch = (Button) findViewById(R.id.btnSerch);
btnSelect = (Button) findViewById(R.id.btnSelect);
btnInsert.setOnClickListener(this);
btnUpdate.setOnClickListener(this);
btnDelete.setOnClickListener(this);
btnSerch.setOnClickListener(this);
btnSelect.setOnClickListener(this);
lstView = (ListView) findViewById(R.id.list);
lstView.setOnItemClickListener(this);
lstView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
dbHandler = DBHandler.open(this);
if (v.getId() == R.id.btnInsert) {
if ( edtCarName.getText().toString().equals("")) {
Toast.makeText(getApplicationContext(), "�̸� �Է�", Toast.LENGTH_LONG).show();
return;
} else if ( edtCarPower.getText().toString().equals("")) {
Toast.makeText(getApplicationContext(), "��ⷮ �Է�", Toast.LENGTH_LONG).show();
return;
}
long re = dbHandler.insert(
edtCarName.getText().toString(),
edtCarPower.getText().toString());
if (re == 0) {
Toast.makeText(getApplicationContext(), "�߰� ����", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "�߰� ����", Toast.LENGTH_LONG).show();
cursor = dbHandler.selectAll();
arr_list = new ArrayList<AdepterDTO>();
while (cursor.moveToNext()) {
String id = cursor.getString(0);
String name = cursor.getString(1);
String power = cursor.getString(2);
AdepterDTO dto = new AdepterDTO(id,name,power);
arr_list.add(dto);
}
cursor.close();
invalidate();
}
} else if (v.getId() == R.id.btnSelect) {
cursor = dbHandler.selectAll();
// arr = new String[cursor.getCount()];
arr_list = new ArrayList<AdepterDTO>();
// int count = 0;
while (cursor.moveToNext()) {
String id = cursor.getString(0);
String name = cursor.getString(1);
String power = cursor.getString(2);
AdepterDTO dto = new AdepterDTO(id, name, power);
arr_list.add(dto);
}
cursor.close();
invalidate();
}else if(v == btnDelete){
String id = edtid.getText().toString();
dbHandler.delete(id);
}else if(v==btnUpdate){
String id = edtid.getText().toString();
String name = edtCarName.getText().toString();
String power = edtCarPower.getText().toString();
dbHandler.update(id,name,power);
}
}
private void invalidate() {
CarAdapter caradapter = new CarAdapter(this, R.layout.itemlist, arr_list);
lstView.setAdapter(caradapter);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, final long id) {
String a = lstView.getItemAtPosition(position).toString();
edtid.setText(a);
edtCarName.setText(a);
edtCarPower.setText(a);
}
public class CarAdapter extends ArrayAdapter<AdepterDTO> {
private ArrayList<AdepterDTO> items;
public CarAdapter(Context context, int textViewResourceId, ArrayList<AdepterDTO> items) {
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int _position, View _convertView, ViewGroup _parent) {
View view = _convertView;
if (view == null) {
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.itemlist,null);
}
AdepterDTO ref = items.get(_position);
if (ref != null) {
TextView txt_id = (TextView) view.findViewById(R.id.id);
TextView txt_name = (TextView) view.findViewById(R.id.name);
TextView txt_power = (TextView) view.findViewById(R.id.power);
if (txt_id != null)
txt_id.setText(ref.getId());
if (txt_name != null)
txt_name.setText(ref.getName());
if (txt_power != null)
txt_power.setText(ref.getPower());
}
return view;
}
}
public class AdepterDTO {
private String id;
private String name;
private String power;
public AdepterDTO(String id, String name, String power) {
this.id = id;
this.name =name;
this.power =power;
}
public String getId() {
return this.id;
}
public String getName() {
return this.name;
}
public String getPower() {
return this.power;
}
}
코드첨부 합니다 ㅜ .. 도와주세요 ㅜ