在片段中,列表视图未显示。这是我的代码。苦苦挣扎解决这个问题....
我从LeaderShip.java调用LeaderList.java来填充framelayout。我从另一个片段调用LeaderShip.java ...
LeaderShip.java
===============
package com.example.listviewtest;
import java.nio.channels.GatheringByteChannel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class LeaderShip extends Fragment {
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
int Position ;
int FirstTime = 1;
//final Context context = this;
private ListAdapter listAdapter1;
private ListView lview;
View convertView = null;
View groupView;
ImageButton imgbutt;
Fragment Fra;
LeaderList listAdapter;
String[] web = {
"Rep. Name (R) Position\n",
"Rep. Name (R) Position\n",
"Rep. Name (R) Position\n",
"Rep. Name (R) Position\n",
"Rep. Name (R) Position\n",
"Rep. Name (R) Position\n",
"Rep. Name (R) Position\n",
"Rep. Name (R) Position\n",
"Rep. Name (R) Position\n"
} ;
Integer[] personimage = {
R.drawable.image1,
R.drawable.image2,
R.drawable.image3,
R.drawable.image4,
R.drawable.image5,
R.drawable.image6,
R.drawable.image7
};
Integer[] mailimage = {
R.drawable.image1,
R.drawable.image2,
R.drawable.image3,
R.drawable.image4,
R.drawable.image5,
R.drawable.image6,
R.drawable.image7
};
Integer[] phoneimage = {
R.drawable.image1,
R.drawable.image2,
R.drawable.image3,
R.drawable.image4,
R.drawable.image5,
R.drawable.image6,
R.drawable.image7
};
Integer[] twitterimage = {
R.drawable.image1,
R.drawable.image2,
R.drawable.image3,
R.drawable.image4,
R.drawable.image5,
R.drawable.image6,
R.drawable.image7
};
Integer[] arrowimage = {
R.drawable.image1,
R.drawable.image2,
R.drawable.image3,
R.drawable.image4,
R.drawable.image5,
R.drawable.image6,
R.drawable.image7
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
//View view = inflater.inflate(R.layout.outagereport, container, false);
View view = inflater.inflate(R.layout.leaderlist, container, false);
//prepareListData();
listAdapter = new LeaderList(getActivity(),1,personimage,mailimage,phoneimage,twitterimage,arrowimage,web);
lview=(ListView)view.findViewById(R.id.LeaderList);
lview.setAdapter(listAdapter);
return view;
}
}
leaderlist.xml
==============
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LeaderFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#04B486">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="@+id/LeaderList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#ffffff"
android:dividerHeight="2dp">
</ListView>
</RelativeLayout>
</FrameLayout>
LeaderList.java
===============
package com.example.listviewtest;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
public class LeaderList extends ArrayAdapter<String> {
private final Activity context;
private final int web;
private final Integer[] expandImage;
private final Integer[] mailImage;
private final Integer[] phoneImage;
private final Integer[] twitterImage;
private final Integer[] personalImage;
private final String [] Title;
ImageButton imageButton;
//private final Integer[] imageId;
public LeaderList(Activity context,
int web,Integer [] personalImage, Integer [] mailImage,Integer [] phoneImage,
Integer [] twitterImage,Integer [] expandImage,String [] Title) {
super(context,web);
this.context = context;
this.web = web;
this.personalImage = personalImage;
this.mailImage = mailImage;
this.phoneImage = phoneImage;
this.twitterImage = twitterImage;
this.expandImage = expandImage;
this.Title = Title;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View convertView= inflater.inflate(R.layout.leadership, parent, false);
TextView lblListHeader = (TextView) convertView.findViewById(R.id.ShowLeadTitle);
ImageView imageview = (ImageView) convertView.findViewById(R.id.representative);
ImageButton mailimageview = (ImageButton) convertView.findViewById(R.id.mailimg);
ImageButton phoneimageview = (ImageButton) convertView.findViewById(R.id.phoneimg);
ImageButton twitterimageview = (ImageButton) convertView.findViewById(R.id.twitterimg);
ImageButton expandimageview = (ImageButton) convertView.findViewById(R.id.arrowimg);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setTextColor(Color.WHITE);
imageview.setImageResource(personalImage[position]);
mailimageview.setImageResource(mailImage[position]);
phoneimageview.setImageResource(phoneImage[position]);
twitterimageview.setImageResource(twitterImage[position]);
expandimageview.setImageResource(expandImage[position]);
return convertView;
}
}
leadership.xml
==============
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:id="@+id/searchLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:scaleType="fitXY" >
<ImageView
android:id="@+id/representative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:src="@drawable/ic_launcher"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/searchLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:scaleType="fitXY" >
<TextView
android:id="@+id/ShowLeadTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:layout_marginTop="20dp"
android:text="Rep. Name (R) Position"
/>
<LinearLayout
android:id="@+id/representLayout"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:orientation="horizontal"
android:scaleType="fitXY" >
<ImageButton
android:id="@+id/mailimg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:src="@drawable/ic_launcher"
/>
<ImageButton
android:id="@+id/phoneimg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_weight="1"
android:layout_marginBottom="5dp"
android:src="@drawable/ic_launcher"
/>
<ImageButton
android:id="@+id/twitterimg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_weight="1"
android:layout_marginBottom="5dp"
android:src="@drawable/ic_launcher"
/>
<ImageButton
android:id="@+id/arrowimg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_weight="1"
android:layout_marginBottom="5dp"
android:src="@drawable/ic_launcher"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
答案 0 :(得分:0)
package com.example.listviewtest;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
public class LeaderList extends ArrayAdapter<String> {
private final Activity context;
private final int web;
private final Integer[] expandImage;
private final Integer[] mailImage;
private final Integer[] phoneImage;
private final Integer[] twitterImage;
private final Integer[] personalImage;
private final String [] Title;
ImageButton imageButton;
//private final Integer[] imageId;
public LeaderList(Activity context,
int web,Integer [] personalImage, Integer [] mailImage,Integer [] phoneImage,
Integer [] twitterImage,Integer [] expandImage,String [] Title) {
super(context,web);
this.context = context;
this.web = web;
this.personalImage = personalImage;
this.mailImage = mailImage;
this.phoneImage = phoneImage;
this.twitterImage = twitterImage;
this.expandImage = expandImage;
this.Title = Title;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View convertView= inflater.inflate(R.layout.leadership, parent, false);
TextView lblListHeader = (TextView) convertView.findViewById(R.id.ShowLeadTitle);
ImageView imageview = (ImageView) convertView.findViewById(R.id.representative);
ImageButton mailimageview = (ImageButton) convertView.findViewById(R.id.mailimg);
ImageButton phoneimageview = (ImageButton) convertView.findViewById(R.id.phoneimg);
ImageButton twitterimageview = (ImageButton) convertView.findViewById(R.id.twitterimg);
ImageButton expandimageview = (ImageButton) convertView.findViewById(R.id.arrowimg);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setTextColor(Color.WHITE);
imageview.setImageResource(personalImage[position]);
mailimageview.setImageResource(mailImage[position]);
phoneimageview.setImageResource(phoneImage[position]);
twitterimageview.setImageResource(twitterImage[position]);
expandimageview.setImageResource(expandImage[position]);
return convertView;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 1;
}
}
试试并说出来。