I'm trying to develop a timeline like facebooks one on below.
You see, I have a ViewPager to navigate user between "Fragments" like feed, profile, about etc..
I have "main.xml" which has just viewpager on it like this;
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
and also I have fragmenta.xml, fragmentb.xml, fragmentc.xml. Lets inspect on fragmenta.xml, inside of it, I put;
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFCC00"
tools:context=".FragmentA" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true">
</ListView>
</FrameLayout>
And made singlerow.xml to create that boxes into a timeline like this;
<?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="wrap_content"
android:orientation="vertical"
android:background="#e67e22"
android:layout_margin=" 5dp">
<ImageView
android:layout_marginTop="5dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/s1" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:layout_gravity="left"
android:textAlignment="gravity"
android:text="16 likes"/>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:layout_gravity="right"
android:textAlignment="gravity"
android:text="43mins ago"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:layout_gravity="left"
android:textAlignment="gravity"
android:text="Like" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:layout_gravity="right"
android:textAlignment="gravity"
android:text="Share"/>
</LinearLayout>
</LinearLayout>
I made it worked with just one static box. But when I try to run this structure I get an error on debug mode "Source not found EDIT SOURCE LOOKUP PATH"
After I tried to put my adapter and other stuffs about listview into fragmentA.java like this;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnCreateContextMenuListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
public class FragmentA extends Fragment {
ListView list;
String[] sLikes;
String[] sTimes;
int[] images={R.drawable.p1, R.drawable.p2,R.drawable.p3};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_a,container,false);
Resources res = getResources();
sLikes=res.getStringArray(R.array.likes);
sTimes=res.getStringArray(R.array.times);
list = (ListView) findViewById(R.id.listView1);
sAdapter adapter = new sAdapter(this, sLikes, images, sTimes);
list.setAdapter(adapter);
}
class sAdapter extends ArrayAdapter<String>
{
Context context;
int[] images;
String[] likesArray;
String[] timesArray;
sAdapter(Context c,String[] likes, int imgs[], String[] tms)
{
super(c,R.layout.singlerow,R.id.textView2,likes);
this.context=c;
this.images=imgs;
this.likesArray=likes;
this.timesArray=tms;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//converting to java object
LayoutInflater inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row=inflater.inflate(R.layout.singlerow,parent,false);
ImageView myImage= (ImageView) row.findViewById(R.id.imageView1);
TextView myLikes = (TextView) row.findViewById(R.id.textView);
TextView myTimes = (TextView) row.findViewById(R.id.textView1);
myImage.setImageResource(images[position]);
myLikes.setText(likesArray[position]);
myTimes.setText(timesArray[position]);
return row;
}
}
}
But in here,
list = (ListView) findViewById(R.id.listView1);
CapsAdapter adapter = new CapsAdapter(this, capsLikes, images, capsTimes);
findViewById
and new CapsAdapter
in underlined with red..
What am I missing here. I should not touch inside of FragmentA.java
? I will create another java document ? Please help me about this.
-I created SingleRow/Bow structure, -I created Fragments / putted adapter etc inside of it, -I pulled them into mainactivity.java document..
Can anyone help me about this ? Thank you.