I have to develop one android application.
Here i have using fragment concept.
<?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"
android:orientation="vertical"
android:id="#+id/_listDetails"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/layout"
>
<ImageView
android:id="#+id/pos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_toLeftOf="#+id/neg"
android:src="#drawable/a_pos_off" />
<ImageView
android:id="#+id/neg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_toLeftOf="#+id/imageView5"
android:src="#drawable/a_neg_off" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/layout"
android:orientation="horizontal" >
<fragment
android:id="#+id/activity_main"
android:name="com.xmlparsing.MainActivity"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
<fragment
android:id="#+id/fragment2"
android:name="com.xmlparsing.SubCate"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
Here i have used Two fragments..They are ., MainActivity.java and SubCate.java
public class AndroidListFragmentActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment);
}}
Here The positive image is there in fragment.xml file...Here if i have to click these positive image which means the have to increase the text size for fullcontent of second fragement (SubCate.java )...
How can i do ??? pls give me solution for these ...
This is my Second Fragment (SubCate.java) code:
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class SubCate extends Fragment
{
int count = 0, i, j;
WebSettings webSettings;
WebView fullcontent;
ImageView positive,negative;
AndroidListFragmentActivity _listDetailsFrag;
View activityView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.subcate,
container, false);
fullcontent = (WebView) view.findViewById(R.id.fullcontent);
Bundle bundle = getArguments();
return view;
}
public void updateDetail(String articlefullcontent) {
_FullContent = articlefullcontent.substring(1);
fullcontent.setWebChromeClient(new WebChromeClient());
webSettings = fullcontent.getSettings();
fullcontent.getSettings();
fullcontent.loadDataWithBaseURL(null, _FullContent, "text/html", "utf-8", null);
positive = ((ImageView )activityView.findViewById(R.id.pos));
positive.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
count++;
if (count == -1)
{
webSettings.setTextSize(WebSettings.TextSize.SMALLER);
positive.setImageResource(R.drawable.a_pos_off);
negative.setImageResource(R.drawable.a_neg_on);
}
else
if (count == 0)
{
webSettings.setTextSize(WebSettings.TextSize.NORMAL);
positive.setImageResource(R.drawable.a_pos_off);
negative.setImageResource(R.drawable.a_neg_off);
}
else
if (count >= 1)
{ count=1;
webSettings.setTextSize(WebSettings.TextSize.LARGER);
positive.setImageResource(R.drawable.a_pos_on);
negative.setImageResource(R.drawable.a_neg_off);
}
}
});
}
}
I have to run the app and click that imageview means the fullcontent text is not increase the value...How can i do ??? please help me and provide me some solution ???
Your fragment can not find the corresponding ImageView. Edit to the next and check:
positive = (ImageView )getActivity().findViewById(R.id.pos);//use getActivity() Method
Related
I want to set the margin on the LinearLayout in activity_main.xml, but because I'm using viewbinding, the margin doesn't show any result. Is there a way to have the margins on the LinearLayout set even when using viewbinding?
build.gradle
android {
viewBinding {
enabled = true
}
}
acivity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:id="#+id/idLayout"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/idText1"
android:textSize="20sp"
android:text="HELLO WORLD"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="click"
android:layout_margin="100dp"
android:id="#+id/idButton1"/>
</LinearLayout>
MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
View view = binding.getRoot();
setContentView(view);
binding.idText1.setText("This is view binding");
binding.idButton1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "binding", Toast.LENGTH_SHORT).show();
}
});
}
I am trying to achieve similar effect to the one found in Todoits application where you can click on FAB and it shows a floating popup for adding new task.
This is how it looks:
The closest to it I managed to achieve is this:
It is nearly there, but I want the popup to be about 10dp above the keyboard and scroll the recycle viewer to the last item but I can't get it there :/ Currently, the popup is centred.
I have tried before adding the popup to the bottom of the screen and setting android:windowSoftInputMode="adjustResize" but this was moving my bottom navigation above the keyboard too. Setting windowsSoftInputMode to panAdjust was cutting away the toolbar and few items from the list.
Have you got any suggestions about how to achieve similar effect to the one in Todoist? Maybe with a DialogFragment?
Below is my current code (navigation bar implementation is still not completed):
MainActivity:
public class MainActivity extends AppCompatActivity {
private WorkoutsListFragment workoutsListFragment;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar myToolbar = findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
ActionBar actionBar = getSupportActionBar();
this.workoutsListFragment = new WorkoutsListFragment();
getSupportFragmentManager()
.beginTransaction()
.add(R.id.main_layout, workoutsListFragment)
.commit();
}
}
WorkoutListFragment:
public class WorkoutsListFragment extends Fragment
implements View.OnClickListener, WorkoutListViewHolderInterface {
private RecyclerView recyclerView;
private WorkoutListRecycleViewAdapter recycleViewAdapter;
private AddBoxView addBoxView;
private FloatingActionButton actionButton;
private InputMethodManager imm;
private WorkoutViewModel workoutViewModel;
private boolean addBoxStatus;
public WorkoutsListFragment() {}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.addBoxStatus = false;
//Irrelevant code removed (Dagger 2 DI)
this.workoutViewModel =
ViewModelProviders.of(this, workoutViewModelFactory).get(WorkoutViewModel.class);
workoutViewModel.init(7);
workoutViewModel.getWorkout().observe(this, w -> this.updateWorkoutsList(w, false));
this.imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
}
#Override
public View onCreateView(
#NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_workouts_list, container, false);
this.recyclerView = view.findViewById(R.id.workoutsList);
// this.recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager recyclerViewLayoutManager = new LinearLayoutManager(getContext());
this.recyclerView.setLayoutManager(recyclerViewLayoutManager);
this.recycleViewAdapter = new WorkoutListRecycleViewAdapter(this);
this.recyclerView.setAdapter(recycleViewAdapter);
this.actionButton = view.findViewById(R.id.floating_action_add_workout);
this.actionButton.setOnClickListener(this);
this.addBoxView = new AddBoxView(Objects.requireNonNull(getContext()));
FrameLayout.LayoutParams addBoxLayoutParams =
new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT,
Gravity.CENTER);
this.addBoxView.setLayoutParams(addBoxLayoutParams);
this.addBoxView.getButton().setOnClickListener(this);
return view;
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.floating_action_add_workout:
this.addBoxView((FrameLayout) v.getParent(), v);
break;
case R.id.overlay_layout:
removeAddBoxView((FrameLayout) v);
break;
case R.id.button:
this.addNewWorkout(this.addBoxView.getInputText());
break;
}
}
//Irrelevant code removed....
private void addBoxView(FrameLayout viewGroup, View v) {
this.addBoxStatus = true;
viewGroup.setClickable(true);
viewGroup.setOnClickListener(this);
viewGroup.setBackgroundColor(
getResources().getColor(R.color.cardview_shadow_start_color, null));
viewGroup.removeView(v);
viewGroup.addView(this.addBoxView);
this.addBoxView.requestInputFocus();
this.imm.showSoftInput(this.addBoxView.getInput(), InputMethodManager.SHOW_IMPLICIT);
}
private void removeAddBoxView(FrameLayout viewGroup) {
viewGroup.setClickable(false);
this.imm.hideSoftInputFromWindow(this.addBoxView.getInput().getWindowToken(), 0);
viewGroup.removeView(this.addBoxView);
viewGroup.setBackgroundColor(getResources().getColor(R.color.cardview_shadow_end_color, null));
viewGroup.addView(this.actionButton);
this.addBoxStatus = false;
}
}
Fragment_workouts_list layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e1e1e1"
android:padding="0dp"
tools:context=".Activities.MainActivity.Fragments.Workouts.WorkoutsListFragment"
tools:layout_editor_absoluteY="81dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/workoutsList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
android:elevation="0dp"
android:scrollbars="vertical"
app:layout_constraintBottom_toTopOf="#+id/add_box_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</android.support.v7.widget.RecyclerView>
<FrameLayout
android:id="#+id/overlay_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:outlineProvider="bounds">
<android.support.design.widget.FloatingActionButton
android:id="#+id/floating_action_add_workout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="40dp"
android:layout_marginEnd="40dp"
android:clickable="true"
android:src="#android:color/holo_blue_dark" />
</FrameLayout>
</FrameLayout>
MainActivity Layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
android:id="#+id/root_view"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/AppTheme.AppBar" />
<FrameLayout
android:id="#+id/main_layout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar">
</FrameLayout>
<android.support.design.widget.BottomNavigationView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#color/colorPrimary"
android:foregroundGravity="bottom"
android:visibility="visible"
app:itemTextColor="#color/textColorWhite"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/my_navigation_items" />
</android.support.constraint.ConstraintLayout>
I am trying to get Admob to display on my layout_one.xml and layout_two and can't get it to show. This app has a lot of swipe left and right and I want to display one ad over both layouts
Here are all my xml layouts:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pager">
</android.support.v4.view.ViewPager>
layout_one.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/relative_one"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Copy"
android:id="#+id/Copy"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_alignParentEnd="false"
android:layout_alignParentStart="false"
android:textSize="30sp"
android:onClick="onClickCopy"/>
<EditText
android:layout_width="300dp"
android:layout_height="50dp"
android:id="#+id/stringCopy"
android:layout_above="#+id/Copy"
android:layout_centerHorizontal="true"
android:layout_marginBottom="70dp"
android:textSize="30sp"
android:inputType="text"
android:gravity="left|top"
android:background="#ffffff" />
<com.google.android.gms.ads.AdView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id"/>
layout_two.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"
android:id="#+id/relative_one"
android:background="#000000"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Paste"
android:id="#+id/Paste"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_alignParentEnd="false"
android:layout_alignParentStart="false"
android:textSize="30sp"
android:onClick="onClickPaste"/>
<EditText
android:layout_width="300dp"
android:layout_height="50dp"
android:id="#+id/stringCopy"
android:layout_marginBottom="71dp"
android:textSize="30sp"
android:inputType="text"
android:gravity="left|top"
android:background="#ffffff"
android:layout_above="#+id/Paste"
android:layout_centerHorizontal="true" />
<!-- SHOULD I PUT ANOTHER ADVIEW IN THIS XML -->
</RelativeLayout>
Here is all my java classes:
MainActivity.java
public class MainActivity extends FragmentActivity {
//View Pager
ViewPager viewpager;
//AdView
AdView adView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewpager = (ViewPager)findViewById(R.id.pager);
PagerAdapter pAdapter = new PagerAdapter(getSupportFragmentManager());
viewpager.setAdapter(pAdapter);
}
public void onClickCopy(View v)
{
//Copy Text From layout_one to Clipboard
}
public void onClickPaste(View v)
{
//Paste Text From Clipboard
}
}
PagerAdapter.java
public class PagerAdapter extends FragmentPagerAdapter {
public PagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int arg0) {
switch (arg0) {
case 0:
return new FragmentOne();
case 1:
return new FragmentTwo();
default:
break;
}
return null;
}
#Override
public int getCount() {
return 2;
}
}
FragmentOne.java
public class FragmentOne extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.layout_one, container, false);
}
}
FragmentTwo.java
public class FragmentTwo extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.layout_two, container, false);
}
}
Where would I put this code so that when they swipe between layout_one and layout_two that the same ad will be displayed and not make a new ad request every time they change views?
//Display test Ads
adView = new AdView(this);
AdRequest request = new AdRequest.Builder()
.addTestDevice("DEVICE_ID").build();
adView.loadAd(request);
The standard pattern for doing this is to put your AdView either above or below your ViewPager and keep it static. That way you are not constantly requesting ads that you never get time to display.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/pager">
</android.support.v4.view.ViewPager>
<com.google.android.gms.ads.AdView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:adUnitId="yourAdUnitId"
android:id="#+id/adView">
</LinearLayout>
This way your Adview is outside your ViewPager and remains constant across all pages.
I use the following code to cache Admob in scroll Grid View:
public View getView(int position, View convertView, ViewGroup parent) {
if (position != adNum) {
...
} else {
if (mAdView == null) {
frameLayout = new FrameLayout(mContext);
mAdView = new AdView(mContext);
...
frameLayout.addView(mAdView);
} else {
frameLayout.removeView(mAdView);
frameLayout = new FrameLayout(mContext);
frameLayout.addView(mAdView);
}
return frameLayout;
}
}
I'm trying to change the weight of "MapView" and "InfoContent" when i click on a button inside the mapview fragment. The mapView Fragment is defined in the PlaceholderFragment2 Java Class.
The first click should change the weight to a new value, while the second click should restore the old value.
XMl:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity"
android:orientation="vertical"
>
<FrameLayout
android:id="#+id/TitleBar"
android:layout_width="fill_parent"
android:layout_height="50dp"
>
</FrameLayout>
<FrameLayout
android:id="#+id/MapView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
</FrameLayout>
<FrameLayout
android:id="#+id/InfoTitleBar"
android:layout_width="fill_parent"
android:layout_height="170dp"
>
</FrameLayout>
<FrameLayout
android:id="#+id/InfoContent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0"
>
</FrameLayout></LinearLayout>
MainActivity.Java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PlaceholderFragment frg=new PlaceholderFragment();
PlaceholderFragment2 frg2=new PlaceholderFragment2();
PlaceholderFragment3 frg3=new PlaceholderFragment3();
PlaceholderFragment4 frg4=new PlaceholderFragment4();
FragmentManager manager=getFragmentManager();
FragmentTransaction transaction=manager.beginTransaction();
transaction.add(R.id.TitleBar, frg, "Frag_Top_tag");
transaction.add(R.id.MapView, frg2, "Frag_Middle_tag");
transaction.add(R.id.InfoTitleBar, frg3, "Frag_Bottom_tag");
transaction.add(R.id.InfoContent, frg4, "Frag_Content_tag");
transaction.commit();
}
And PlaceHolderFragment2.java
public static class PlaceholderFragment2 extends Fragment {
public PlaceholderFragment2() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.mapview, container,
false);
final Button button =
(Button) rootView.findViewById(R.id.zoomMap);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
buttonClicked(v);
}
});
return rootView;
}
I solved it, I put the fragment in linear layout, then in the main activity I created the object, when I click just change the size of the weight of the linear layout, cos' I do not need nor by the fragment transaction.
MainActivity
private Button button;
private LinearLayout layoutListView;
private LinearLayout.LayoutParams lpListView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_container);
button = (Button) findViewById(R.id.button);
layoutListView = (LinearLayout) findViewById(R.id.listTreeView);
lpListView = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT);
lpListView.weight = 20;
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (lpListView.weight == 0) {
lpListView.weight = 20;
} else {
lpListView.weight = 0;
}
layoutListView.setLayoutParams(lpListView);
}
});
}
}
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="100"
android:orientation="horizontal"
android:weightSum="100" >
<LinearLayout
android:id="#+id/listTreeView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="20"
android:orientation="horizontal" >
<fragment
android:id="#+id/fraglistView"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.ListTreeView" />
</LinearLayout>
<LinearLayout
android:id="#+id/fragbutton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="80"
android:background="#F000" >
<fragment
android:id="#+id/fraglistRight"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.ListViewRight" />
</LinearLayout>
</LinearLayout>
This is my code:
.......
CollectionPagerAdapter mCollectionPagerAdapter;
ViewPager mViewPager;
#Override
protected void onCreate(Bundle savedInstanceState) { Log.i("App", "U reaching Da onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.main_fragment);
mCollectionPagerAdapter =
new CollectionPagerAdapter(
getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.CardsPager);
mViewPager.setAdapter(mCollectionPagerAdapter);
....
//ADAPTER:
class CollectionPagerAdapter extends FragmentStatePagerAdapter {
public CollectionPagerAdapter(android.support.v4.app.FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int i) {
Fragment fragment = new ObjectFragment();
Bundle args = new Bundle();
// Our object is just an integer :-P
args.putInt(ObjectFragment.ARG_OBJECT, i + 1);
fragment.setArguments(args);
Log.i("App", "U reaching Da Adapter!!");
return fragment;
}
#Override
public int getCount() {
return 100;
}
#Override
public CharSequence getPageTitle(int position) {
return "OBJECT " + (position + 1);
}
}
.....
//ObjectFragment.java
public class ObjectFragment extends Fragment {
public static final String ARG_OBJECT = "object";
#Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
// The last two arguments ensure LayoutParams are inflated
// properly.
View rootView = inflater.inflate(
R.layout.cards_pager, container, false);
Bundle args = getArguments();
((TextView) rootView.findViewById(android.R.id.text1)).setText(
Integer.toString(args.getInt(ARG_OBJECT)));
Log.i("App", "U reaching Da inflater Y U no work?!");
return rootView;
}
}
main_fragment.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="100" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="40"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#109922" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="20"
android:orientation="vertical"
android:background="#115599">
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/CardsPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000" >
</android.support.v4.view.ViewPager>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="40"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ff9922">
</LinearLayout>
</LinearLayout>
It seems like the app never reach the adapter.
I did exactly as the android developers guide.
I don't know what's going on here, eclipse let me run the app and everyting seems to be fine in the code but it just no working
I finally got it right,
the problem is that I have set the adapter in the onCreate() methhod,
to solve this problem I have set the adapter in the onCreateView() methhod in the MainFragment.