I'm new android..my english little bit:(
I want develop multi pane app.
Two fragments "Gridview" and "Full screen"
I know multi pane, but i dont know Gridview and Full screen in multi pane.
Because all samples for ListView.
help me please
this app good for me but too complex=
http://www.codeproject.com/Articles/779293/Building-Dynamic-UI-for-Android-Devices
Its a simple implementation if i understand your question correctly
------------- Creating GridView ------------
For GridView you need an adapter for your GridView Object and images for columns, an example using country list and flag images,
Create drawable folder inside res and add country flag images inside drawable folder
Create gridlayout.xml in res/layout
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#drawable/border"
android:padding="5dp">
<ImageView
android:id="#+id/gridimage"
android:layout_height="65dp"
android:layout_width="65dp"
android:src="#drawable/icon"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
</ImageView>
<TextView
android:id="#+id/gridtext"
android:text="TextView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#+id/imageView1"
android:layout_marginTop="2dp"
android:layout_centerHorizontal="true"
android:textSize="18sp"
android:ellipsize="marquee"></TextView>
</RelativeLayout>
Create gridrow.xml in res/Layout folder
<GridView
android:id="#+id/gridView1"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:numColumns="auto_fit"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp">
</GridView>
Create GridAdapter.java class
public class GridAdapter extends BaseAdapter {
private ArrayList<String> CountryList;
private ArrayList<Integer> CountryFlag;
private Activity activity;
public GridAdapter(Activity activity,ArrayList<String> CountryList, ArrayList<Integer> CountryFlag){
super();this.CountryList = CountryList;
this.CountryFlag = CountryFlag;
this.activity = activity;}
#Override
public int getCount() {
return CountryList.size();
}
#Override
public String getItem(int position) {
return CountryList.get(position);
}
#Override
public long getItemId(int position) {
return 0;
}
public static class ViewHolder
{
public ImageView imgViewFlag;
public TextView txtViewTitle;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder view;
LayoutInflater inflator = activity.getLayoutInflater();
if(convertView==null)
{
view = new ViewHolder();
convertView = inflator.inflate(R.layout.gridview_row, null);
view.txtViewTitle = (TextView) convertView.findViewById(R.id.gridtext);
view.imgViewFlag = (ImageView) convertView.findViewById(R.id.gridimage);
convertView.setTag(view);
}
else
{
view = (ViewHolder) convertView.getTag();
}
view.txtViewTitle.setText(CountryList.get(position));
view.imgViewFlag.setImageResource(CountryFlag.get(position));
return convertView;
}
}
Create Fragment GridViewActivty
public class GridViewActivty extends Fragment {
private ArrayList CountryList = new ArrayList();
private ArrayList CountryFlag = new ArrayList();
private GridView mygrid;
private GridAdapter adapter;
private Context context;
public GridViewActivty(){}
#Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState)
{ View rootView = inflater.inflate(R.layout.gridlayout.xml, container, false);
CountryList = new ArrayList<String>();
CountryList.add("South Africa");
CountryList.add("Spain");
CountryList.add("Canada");
CountryList.add("China");
CountryList.add("France");
CountryList.add("Germany");
CountryList.add("Iran");
CountryList.add("Italy");
CountryList.add("Japan");
CountryList.add("Korea");
CountryList.add("Mexico");
CountryList.add("Netherlands");
CountryFlag = new ArrayList<Integer>();
CountryFlag.add(R.drawable.southafrica);
CountryFlag.add(R.drawable.spain);
CountryFlag.add(R.drawable.canada);
CountryFlag.add(R.drawable.china);
CountryFlag.add(R.drawable.france);
CountryFlag.add(R.drawable.germany);
CountryFlag.add(R.drawable.iran);
CountryFlag.add(R.drawable.italy);
CountryFlag.add(R.drawable.japan);
CountryFlag.add(R.drawable.korea);
CountryFlag.add(R.drawable.mexico);
CountryFlag.add(R.drawable.netherlands);
adapter = new GridAdapter(this.getActivity(),CountryList, CountryFlag);
mygrid = (GridView)rootView.findViewById(R.id.gridview1);
mygrid.setAdapter(adapter);
mygrid.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
}
}
);
return rootView;
}
}
----------- Creating Full Screen --------
Create fullscreen.xml inside Layout Folder
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
>
Create FullScreen.java Fragment
public class Fullscreen extends Fragment{ #Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
savedInstanceState)
{ View rootView = inflater.inflate(R.layout.fullscreen.xml, container, false);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
return convertView; }
Related
I Created custom grid view with product list based on web service(json).but i facing new issue.when i set size(100dp) for image view height & width it working perfectly.but i set wrap_content or match parent it's view images are blink & blink again..
my fragment class :
public class HorizontalAdapter extends BaseAdapter {
private ArrayList<HomeCategoriesData> mArrayList;
private Context mContext;
private LayoutInflater mLayoutInflater;
public HorizontalAdapter(Activity homeActivity, ArrayList<HomeCategoriesData> mArrayList) {
this.mContext = homeActivity;
this.mArrayList = mArrayList;
mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
return mArrayList.size();
}
#Override
public Object getItem(int position) {
return mArrayList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder mViewHolder;
if (convertView == null) {
mViewHolder = new ViewHolder();
convertView = mLayoutInflater.inflate(R.layout.item_categories_item, null);
mViewHolder.mTvName = (TextView) convertView.findViewById(R.id.tv_categories_name);
mViewHolder.mIvimage = (ImageView) convertView.findViewById(R.id.iv_categories_img);
convertView.setTag(mViewHolder);
} else {
mViewHolder = (ViewHolder) convertView.getTag();
}
mViewHolder.mTvName.setText(mArrayList.get(position).getName());
Picasso.with(mContext).load(mArrayList.get(position).getCat_img()).into(mViewHolder.mIvimage);
convertView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(mContext,mArrayList.get(position).getName(),Toast.LENGTH_SHORT).show();
//calling fragment from adatper class...
SellerSubCategoryFragment frag = new SellerSubCategoryFragment();
FragmentManager fm = ((MainActivity)mContext).getSupportFragmentManager();
Bundle bundle = new Bundle();
bundle.putString("id", String.valueOf(mArrayList.get(position).getId()));
frag.setArguments(bundle);
fm.beginTransaction().replace(R.id.content_frame,frag).addToBackStack(null).commit();
}
});
return convertView;
}
private class ViewHolder {
TextView mTvName;
ImageView mIvimage;
}
}
my adapter class xml file :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/iv_categories_img"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter" />
<TextView
android:id="#+id/tv_categories_name"
style="#android:style/TextAppearance.Small"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_top_categories_name_5"
android:gravity="center"
android:lines="1"
android:textColor="#color/black" />
</LinearLayout>
my out put issue are ,
so what i do? and what is the problem.why i cannot set wrap_content or match_parent in this grid view?. my custom grid view are ExpandapleHeightGridView
I have a custom gridView and inside it i am having two images in a relative layout . Now when i click on the gridView i want the visibility of my images to change.
MainActivity:
public class Main extends Fragment implements OnMapReadyCallback{
GridView gridview,video_gridview;
GridViewAdapter adapter;
View v;
public Main() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
v = inflater.inflate(R.layout.activity_main,
container, false);
gridview = (GridView)v.findViewById(R.id.sub_notify_gridView);
gridview.setNumColumns(3);
adapter = new GridViewAdapter(getActivity(),FilePathStrings,
FileNameStrings,Image_Status,time);
gridview.setAdapter(adapter);
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, final int
position, long id) {
//here i need to know which image has been clicked
}
});
return v;
}
MainActivity Layout:
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".35"
android:id="#+id/sub_notify_gridView">
<!--<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/gridViewImageid"/>-->
</GridView>
Cusotm GridView Adapter:
public class GridViewAdapter extends BaseAdapter {
// Declare variables
private Activity context;
private String[] filepath;
private String[] imageStatus;
private String Imgtime;
String[] separated;
private static LayoutInflater inflater = null;
public GridViewAdapter(FragmentActivity activity, String[] fpath, String[] fname, String[] image_status, String time) {
context = activity;
filepath = fpath;
imageStatus = image_status;
Imgtime = time;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return filepath.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.gridview_item, null);
//TextView text = (TextView) vi.findViewById(R.id.text);
final ImageView image = (ImageView) vi.findViewById(R.id.image);
ImageView upload_image = (ImageView) vi.findViewById(R.id.upload_image);
TextView time = (TextView) vi.findViewById(R.id.textView);
time.setText(Imgtime);
image.setScaleType(ImageView.ScaleType.FIT_XY);
image.setPadding(5, 3, 5, 2); //itrb
//text.setText(filename[position]);
Bitmap ThumbImage =ThumbnailUtils.extractThumbnail
(BitmapFactory.decodeFile(filepath[position]),
128, 128);
if(imageStatus[position].equals("0")){
upload_image.setVisibility(View.VISIBLE);
}
if (filepath[position] == null){
image.setImageResource(R.drawable.imageicon);
}
else{
if (position > 4){
image.setImageBitmap(ThumbImage);
}
else{
image.setImageBitmap(ThumbImage);
}
}
return vi;
}
GridView_item Layout File:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:custom="http://schemas.android.com/tools"
android:padding="5dip">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_alignBottom="#+id/image"
android:layout_alignRight="#+id/image"
android:layout_alignEnd="#+id/image"
android:paddingRight="5dp"
android:paddingBottom="1.5dp"
android:id="#+id/textView" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:paddingBottom="1.5dp"
android:id="#+id/upload_image"
android:visibility="gone"
android:src="#drawable/accept_icon"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
I am Trying to insert GridView in fragment. I have developed custom adapter to populate the gridview. Now everything is working fine but the gridview is not displaying in the fragment. I have check the getCount() method it is returning total length. So that means data is there but it is not displaying. I am pretty new with gridview so have no idea why it is happening. I tried the following answer but they didn't help me either.
Android: getView in adapter never called
Custom Adapter getView() method is not called
Gridview not displaying in fragment
Here is my code:
Tile Fragment Class:
public class TileFragment extends Fragment
{
public TileFragment(){
}
GridView gv;
Context context;
public static String [] prgmNameList={"Let Us C","c++","JAVA","Jsp","Microsoft .Net","Android","PHP","Jquery","JavaScript"};
public static int [] prgmImages={R.mipmap.dicover_disable,R.mipmap.discover_active, R.mipmap.home_disable,
R.mipmap.home_active,R.mipmap.lists_disable,R.mipmap.lists_active,
R.mipmap.profile_disable,R.mipmap.profile_active,R.mipmap.ic_search };
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
#SuppressLint("InflateParams")
// View v = LayoutInflater.from(getActivity()).inflate(R.layout.tile_fragment, null);
View v = inflater.inflate(R.layout.tile_fragment, container, false);
gv = (GridView) v.findViewById(R.id.gridView1);
gv.setAdapter(new CustomAdapter(getActivity(), prgmNameList,prgmImages));
return v;
}
#Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
}
}
Custom Adapter:
public class CustomAdapter extends BaseAdapter {
String [] result;
Context context;
int [] imageId;
private static LayoutInflater inflater=null;
public CustomAdapter(FragmentActivity tileFragment, String[] prgmNameList, int[] prgmImages) {
result=prgmNameList;
imageId=prgmImages;
context = tileFragment;
inflater = ( LayoutInflater )context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
return imageId.length;
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
public class Holder
{
TextView tv;
ImageView img;
}
#SuppressLint("ViewHolder")
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
Holder holder=new Holder();
View rowView;
rowView = inflater.inflate(R.layout.programlist, null);
holder.tv=(TextView) rowView.findViewById(R.id.textView1);
holder.img=(ImageView) rowView.findViewById(R.id.imageView1);
holder.tv.setText(result[position]);
holder.img.setImageResource(imageId[position]);
rowView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(context, "You Clicked " + result[position], Toast.LENGTH_LONG).show();
}
});
return rowView;
}
}
tile_fragment:
<?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" >
<GridView
android:id="#+id/gridView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:numColumns="3"
android:visibility="visible">
</GridView>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textStyle="bold"
android:text=" Computer Languages..." />
</RelativeLayout>
prgramlist
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_gravity="center"
android:layout_width="88dp"
android:layout_height="88dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/textView1"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:text="TextView" />
</LinearLayout>
This is how I am adding the fragment:
HomeFragment:
public class HomeFragment extends Fragment
{
public HomeFragment() {
}
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
FragmentTabHost mTabHost = new FragmentTabHost(getActivity());
mTabHost.setup(getActivity(), getChildFragmentManager());
Bundle b = new Bundle();
b.putString("key", "Tile");
mTabHost.addTab(mTabHost.newTabSpec("tile").setIndicator("Tile"), TileFragment.class, b);
//
b = new Bundle();
b.putString("key", "Map");
mTabHost.addTab(mTabHost.newTabSpec("map").setIndicator("Map"), ProfileFragment.class, b);
return mTabHost;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
//
}
Any Help will be appreciated ...
Try this:
mTabHost.setup(getActivity(), getChildFragmentManager(), R.layout.my_parent_fragment);
where R.layout.my_parent_fragment is your layout fragment where you have the tabhost.
Once you have verified that the GridView is displayed correctly in an Activity, we could deduce that this is not a problem with the Gridview neither the Adapter, the problem come from your FragmentTabHost definition or setup. You are returning your tabHost from your onCreateView(), for that you must set your layout or container in your tabHost, if you don't do this, how the fragment know where find your layout?
For more info, api here
Can't figure out the root of the problem but try this:
View rowView = convertView;
if(rowView != null) {
rowView = inflater.inflate(R.layout.programlist, null);
}
Try using this layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent" >
<GridView
android:id="#+id/gridView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"
>
</GridView>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textStyle="bold"
android:text=" Computer Languages..." />
</LinearLayout>
I'm trying to create a custom gridview inside a fragment that should look something like this:
http://imgur.com/6fEFYTN
So I created a FragmentLayout that contains the image and the label:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/grid_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
/>
<TextView
android:id="#+id/grid_label"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:layout_marginTop="175dp"
android:background="#drawable/label"
android:gravity="center"
android:textColor="#FFFFFF"
android:textSize="12sp"
android:textStyle="bold" />
The adapter that manages the FragmentLayout looks like this:
public class CustomGridAdapter extends BaseAdapter{
private Context mContext;
private final String[] label;
private final int[] imgId;
public CustomGridAdapter(Context c,String[] label,int[] imgId ) {
mContext = c;
this.imgId = imgId;
this.label = label;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View grid;
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
grid = new View(mContext);
grid = inflater.inflate(R.layout.image_button_layout, null);
TextView textView = (TextView) grid.findViewById(R.id.grid_label);
ImageView imageView = (ImageView)grid.findViewById(R.id.grid_image);
textView.setText(label[position]);
imageView.setImageResource(imgId[position]);
} else {
grid = (View) convertView;
}
return grid;
}
}
The fragment grid is as follows:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<GridView
android:numColumns="auto_fit"
android:gravity="center"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/form_grid"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
/>
</LinearLayout>
I'm creating this from the onCreateView method, I'm using onclickListener so the images work as buttons and display a toast when pressed:
#Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_layout_softdrinks, container, false);
GridView grid = (GridView) rootView.findViewById(R.id.form_grid);
CustomGridAdapter adapter = new CustomGridAdapter(rootView.getContext(), label, imgId); //label and imgId are arrays containing strings and int respectively
grid.setAdapter(adapter);
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(inflater.getContext(), "You Clicked at " +label[+ position], Toast.LENGTH_SHORT).show();
}
});
return rootView;
}
The problem is that when I run the code, the screen is blank, so the gridview is not being populated.
Any advice on this?
First of all you will need to provide a payload in imgId array and label array.
Then your grid view won't inflate as well because you are returning 0 in your getCount method!
To inflate your layout replace in your getCount method
Return 0;
With
Return imgId.length;
The getCount method tells the base adapter how much images or strings(..data) you have in your array which you want to inflate in the grid view. If you returning 0, base adapter thinks that there are 0 data to inflate.
i want to change my android app in that way, that i implements fragments. In the Mainactivity i am getting the content from a xml file, that i want to populate with the listview in a fragment. But unfortunatey it doesnt work, please can you help me? Here are the codes.
The fragments layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FF00"
android:drawSelectorOnTop="false" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toptext"/>
</LinearLayout>
And this is the fragment file:
public class RoomFragment extends ListFragment {
public RoomFragment() {
}
private MyArrayAdapter mAdapter;
public static final String ARG_SECTION_NUMBER = "section_number";
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
((Dailyquran)getActivity()).main(); // Here I am calling the method in the parent activity to get the content from the xml file. It fills "Tweets"
Dailyquran basem = (Dailyquran)getActivity();
View v = inflater.inflate(R.layout.fragmentlayout, container, false);
final ListView lv = getListView();
mAdapter = new MyArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, basem.tweets);
lv.setAdapter(mAdapter);
return v;
}
public class MyArrayAdapter extends ArrayAdapter<Tweet>
{
Context mContext;
private ArrayList<Tweet> tweets;
Tweet data;
public MyArrayAdapter(Context context, int textViewResourceId, ArrayList<Tweet> items)
{
super(context,textViewResourceId, items);
mContext = context;
this.tweets = items;
}
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
if(row == null)
{
LayoutInflater inflater =((Activity)mContext).getLayoutInflater();
row = inflater.inflate(R.layout.fragmentlayout, null, false);
TextView tt = (TextView) row.findViewById(R.id.toptext);
}
else
{
TextView tt = (TextView) row.findViewById(R.id.toptext);
}
Tweet o = tweets.get(position);
TextView tt = (TextView) row.findViewById(R.id.toptext);
String survers=o.content;
tt.setText(survers);
return row;
}
}
}
You simply need to use the appropriate id in your ListView:
android:id="#android:id/list"