안드로이드 개발 질문/답변
(글 수 45,052)
import java.util.ArrayList;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class ListExample extends ListActivity{ @Override
public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
setContentView(R.layout.work);
ArrayList<Person> m_orders = new ArrayList<Person>();
Person p1 = new Person("1번", "박씨"); Person p2 = new Person("2번", "김씨"); Person p3 = new Person("3번", "이씨");m_orders.add(p1);
m_orders.add(p2);m_orders.add(p3);
PersonAdapter m_adapter = new PersonAdapter(this, R.layout.row, m_orders);
setListAdapter(m_adapter);
}
private class PersonAdapter extends ArrayAdapter<Person> {private ArrayList<Person> items;
public PersonAdapter(Context context, int textViewResourceId, ArrayList<Person> items) {super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {View v = convertView;
if (v == null) {LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
}
Person p = items.get(position);
if (p != null) {TextView tt = (TextView) v.findViewById(R.id.toptext);
TextView bt = (TextView) v.findViewById(R.id.bottomtext);
if (tt != null){tt.setText(p.getName());
}
if(bt != null){bt.setText(p.getNumber());
}
}
return v;
}
}
class Person {private String Name;
private String Number;
public Person(String _Name, String _Number){this.Name = _Name;
this.Number = _Number;
}
public String getName() {return Name;
}
public String getNumber() {return Number;
}
}
}
이렇게 리스트 뷰를 짰습니다
예를 들면
여기서 p1을 클릭하면 네이버로,
p2를 클릭하면 네이트로,
p3을 클릭하면 다음으로
웹뷰가 띄워지는 식으로
각각 아이템에 대해 인텐트를 주고 싶은데
어떻게 쓰면 될 지요?




ListActivity 쓰셨으니깐 onListItemClick(ListView l, View v, int position, long id) 오버라이드해서 거기서 해결하시면 됩니다.