任何人都可以帮助我吗?
如何在android中的另一个ListView
中添加ListView
作为行项?
我的要求如下图所示。
这是ListView
的自定义适配器的代码,其中不包含子ListView
:
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
final ViewHolder holder;
if(convertView==null) {
vi = inflater.inflate(R.layout.tulisan_list_item, null);
holder = new ViewHolder();
holder.id_tulisan = (TextView)vi.findViewById(R.id.id_tulisan);
holder.judul = (TextView)vi.findViewById(R.id.judul);
holder.judul_seo = (TextView)vi.findViewById(R.id.judul_seo);
holder.date = (TextView)vi.findViewById(R.id.date);
holder.sekilas_isi = (TextView)vi.findViewById(R.id.sekilas_isi);
holder.CommentLayout =(LinearLayout)vi.findViewById(R.id.CommentLayout);
holder.dibaca = (TextView)vi.findViewById(R.id.dibaca);
holder.komentar = (TextView)vi.findViewById(R.id.komentar);
holder.gambar_tulisan_detail = (TextView)vi.findViewById(R.id.gambar_tulisan_detail);
holder.status_gambar = (TextView)vi.findViewById(R.id.status_gambar);
holder.thumb_image=(ImageView)vi.findViewById(R.id.gambar_tulisan);
holder.favorite=(ImageButton)vi.findViewById(R.id.favorite);
holder.share=(ImageButton)vi.findViewById(R.id.share);
holder.favorite_anim=(ImageView)vi.findViewById(R.id.favorite_anim);
holder.isi_layout=(LinearLayout)vi.findViewById(R.id.isi_layout);
holder.favorite_anim.setVisibility(View.GONE);
vi.setTag(holder);
} else {
holder = (ViewHolder) vi.getTag();
}
HashMap<String, String> tulisan = new HashMap<String, String>();
tulisan = data.get(position);
// Setting all values in listview
String varjudul=tulisan.get(FavoriteActivity.TAG_JUDUL);
holder.judul.setText(Html.fromHtml(varjudul));
holder.judul_seo.setText(tulisan.get(ContentActivity.TAG_JUDUL_SEO));
holder.id_tulisan.setText(tulisan.get(ContentActivity.TAG_ID));
holder.date.setText(tulisan.get(ContentActivity.TAG_DATE));
String varSekilasIsi=tulisan.get(FavoriteActivity.TAG_SEKILAS_ISI);
holder.sekilas_isi.setText(Html.fromHtml(varSekilasIsi));
holder.dibaca.setText(tulisan.get(ContentActivity.TAG_DIBACA));
// komentar.setText(tulisan.get(ContentActivity.TAG_KOMENTAR));
String gambar_string = tulisan.get(ContentActivity.TAG_GAMBAR);
String gambar_path_string = tulisan.get(ContentActivity.TAG_GAMBAR_PATH);
final String kategori = tulisan.get(ContentActivity.TAG_KATEGORI);
if(gambar_path_string.contains("droidersuin")){
holder.status_gambar.setText(gambar_string);
}
else{
holder.status_gambar.setText("");
}
holder.gambar_tulisan_detail.setText(gambar_path_string);
if(hide_gambar.equals("Y")){
if (isVisible!=1) {
holder.thumb_image.setVisibility(View.GONE);
} else {
if(!gambar_path_string.equals("") ){
holder.thumb_image.setVisibility(View.VISIBLE);
imageLoader.DisplayImage(gambar_path_string, holder.thumb_image);
}
else{
holder.thumb_image.setVisibility(View.GONE);
}
}
}
else{
if (isVisible!=1) {
holder.thumb_image.setVisibility(View.GONE);
} else {
if(!gambar_path_string.equals("") ){
holder.thumb_image.setVisibility(View.VISIBLE);
imageLoader.DisplayImage(gambar_path_string, holder.thumb_image);
}
else{
holder.thumb_image.setVisibility(View.GONE);
}
}
}
DatabaseHandler tulisanDb = new DatabaseHandler(activity);
boolean tulisanListSqllite = tulisanDb.isFavorite(tulisan.get(ContentActivity.TAG_ID));
if(!tulisanListSqllite){
holder.favorite.setImageResource(R.drawable.favorite_noactive);
}
else{
holder.favorite.setImageResource(R.drawable.favorite_active);
}
holder.favorite.setOnClickListener(new android.view.View.OnClickListener()
{
String varid_tulisan = holder.id_tulisan.getText().toString();
boolean s_act;
public void onClick(View v)
{
DatabaseHandler tulisanDb = new DatabaseHandler(activity);
boolean tulisanListSqllite = tulisanDb.isFavorite(varid_tulisan);
if(!tulisanListSqllite){
s_act = tulisanDb.updateFavorite(varid_tulisan,"Y");
if(s_act==true){
holder.favorite.setImageResource(R.drawable.favorite_active);
holder.favorite_anim.setVisibility(View.VISIBLE);
anim_favorite = AnimationUtils.loadAnimation(activity, R.anim.anim_favoriting );
holder.favorite_anim.startAnimation(anim_favorite);
Handler handler = new Handler();
handler.postDelayed(new Runnable(){
@Override
public void run(){
holder.favorite_anim.setVisibility(View.GONE);
holder.favorite_anim.clearAnimation();
}
}, 300);
}
else{
holder.favorite.setImageResource(R.drawable.favorite_noactive);
}
}
else{
s_act = tulisanDb.updateFavorite(varid_tulisan,"N");
if(s_act==true){
holder.favorite.setImageResource(R.drawable.favorite_noactive);
}
else{
holder.favorite.setImageResource(R.drawable.favorite_active);
}
}
}
});
holder.share.setOnClickListener(new android.view.View.OnClickListener()
{
String varjudul = holder.judul.getText().toString();
String varlink = "http://droidersuin.com/tulisan-"+holder.id_tulisan.getText().toString()+"-"+holder.judul_seo.getText().toString()+".html";
String tagMainKategori = String.valueOf(ContentActivity.varheader.charAt(0)).toUpperCase() + ContentActivity.varheader.substring(1, ContentActivity.varheader.length()).replaceAll(" ", "");
String tagKategori=String.valueOf(kategori.charAt(0)).toUpperCase() + kategori.substring(1, kategori.length()).replaceAll(" ", "").replaceAll("&", "Dan").replaceAll("-", "_");
public void onClick(View v)
{
Intent share_this = new Intent(android.content.Intent.ACTION_SEND);
share_this.setType("text/plain");
share_this.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
// Add data to the intent, the receiving app will decide
// what to do with it.
share_this.putExtra(Intent.EXTRA_TEXT,"Via @DroidersUIN App "+"#"+tagMainKategori+" "+"#"+tagKategori+" "+"\""+varjudul +"\" >> "+varlink);
activity.startActivity(Intent.createChooser(share_this, "Share "+
ContentActivity.varheader +" "+kategori));
}
});
holder.isi_layout.setOnClickListener(new android.view.View.OnClickListener(){
// getting values from selected ListItem
String varjudul = holder.judul.getText().toString();
String varsekilas_isi = holder.sekilas_isi.getText().toString();
String vardate = holder.date.getText().toString();
String vargambar_tulisan_detail = holder.gambar_tulisan_detail.getText().toString();
String varid_tulisan = holder.id_tulisan.getText().toString();
String varstatus_gambar= holder.status_gambar.getText().toString();
String main_kategori = ContentActivity.varheader;
String seo_detail = holder.judul_seo.getText().toString();
public void onClick(View v)
{
/*
Toast toast = Toast.makeText(InboxActivity.this, judul, Toast.LENGTH_LONG).show(); */
Intent i = null;
i = new Intent(activity, DetailIsi.class);
Bundle b = new Bundle();
b.putString("judul", varjudul);
b.putString("sekilas_isi_detail", varsekilas_isi);
b.putString("date", vardate);
b.putString("id_tulisan_detail", varid_tulisan);
b.putString("gambar_tulisan_detail", vargambar_tulisan_detail);
b.putString("status_gambar_detail", varstatus_gambar);
b.putString("kategori_detail", kategori);
b.putString("main_kategori_detail", main_kategori);
b.putString("seo_detail", seo_detail);
i.putExtras(b);
activity.startActivity(i);
activity.overridePendingTransition (R.anim.push_left_in, R.anim.push_left_out);
}
});
return vi;
}
如果以上述方式实施上述要求是可能的,还是有更好的方法可以做到这一点?