I am using MergeRecycleAdapter with recyclerview to add multiple views and adapters.When I put them inside cardview and Edittext view is focused keyboard is opening and immediately closing.Without cardview it works fine like Resizing screen. For that I have written one sample activity.I couldn't figure out where I am missing.
Manifest
<activity
android:name=".activity.KeyboardActivity"
android:configChanges="navigation|orientation|screenSize"
android:label="#string/ibhubs"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Layout xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="afterDescendants"
android:focusable="false"
android:isScrollContainer="false" />
</android.support.v7.widget.CardView>
</LinearLayout>
Activity code
public class KeyboardActivity extends BaseActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.keyboard_merge_recycler_adapter);
initializeViews();
}
private void initializeViews() {
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
MergeRecycleAdapter mergeRecycleAdapter = new MergeRecycleAdapter();
for (int i = 0; i < 10; i++) {
EditText editText = new EditText(this);
editText.setText(String.valueOf(i));
mergeRecycleAdapter.addView(editText);
}
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(mergeRecycleAdapter);
}
}
Related
This bounty has ended. Answers to this question are eligible for a +50 reputation bounty. Bounty grace period ends in 6 hours.
M. Usman Khan wants to draw more attention to this question:
Please somebody tell us how to trigger multi-window. Specially for Android 13 and above
My app contains a button through that button just want to trigger split screen functionality
Try to use setSplitScreenState(boolean) to trigger split screen functionality
Example
inside button
onClick{
ActivityManager manager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
if(manager != null){
manager.setSplitState(true);
}
}
R.layout.activity_main (xml)
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button"
android:onClick="startNewActivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
tools:layout_editor_absoluteX="148dp"
tools:layout_editor_absoluteY="297dp" />
</android.support.constraint.ConstraintLayout>
R.layout.activity_second (xml)
(Just a textView to keep it simple)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_gravity="center_horizontal"
android:text="Second Activity" />
</LinearLayout>
Then your MainActivity launch second activity from first activity when Start button is clicked and set Flags. Rect takes care of the switching in division and activity option takes care of the transiting animation;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void startNewActivity(View view) {
Intent i = new Intent(this, SecondActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT |
Intent.FLAG_ACTIVITY_MULTIPLE_TASK |
Intent.FLAG_ACTIVITY_NEW_TASK);
Rect rt = new Rect(0, 0, 100, 100)
ActivityOptions actoptions = ActivityOptions.makeBasic();
ActivityOptions bounds = actoptions.setLaunchBounds(rt);
startActivity(i);
}
}
For this example, nothing I am going to leave the second activity as is.
SecondActivity
public class SecondActivity extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
}
}
Finally and most importantly MainActivity.this in your manifest.xml file should look like this;
<activity android:name=".MainActivity"
android:resizeableActivity="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
To switch into multi window mode long press on the overview button and drag the app to one side of the screen
That's all.
I have been struggling to put this to work. The app resizes well as long as i keep the status bar visible. According to this post it is an android bug, but the issue is closed but not resolved.
From all that i read, playing with Insets should do the trick but i can't put it to work. Not sure even if should go this way.
Following this post i added the below code to OnCreate.
ViewCompat.setOnApplyWindowInsetsListener(getWindow().getDecorView().getRootView(), new OnApplyWindowInsetsListener() {
#Override
public WindowInsetsCompat onApplyWindowInsets(View view, WindowInsetsCompat insets) {
((ViewGroup.MarginLayoutParams) view.getLayoutParams()).topMargin =
insets.getSystemWindowInsetTop();
return insets.consumeSystemWindowInsets();
}
});
It throws the exception:
java.lang.ClassCastException: android.view.WindowManager$LayoutParams
cannot be cast to android.view.ViewGroup$MarginLayoutParams
The post goes on but i am stuck here and have doubts if i am going the right way.
Bellow the testing code i am using if someone wants to try.
Works well until the statusbar is removed by adding <item name="android:windowFullscreen">true</item> to AppTheme.
AndroidManifest.xml:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
activity_mail.xml:
<!-- this control should be position static -->
<TextView
android:layout_height="50dp"
android:layout_width="fill_parent"
android:background="#color/colorPrimaryDark"
android:text="static window at top"
android:gravity="center"
/>
<!-- the resizable view -->
<android.support.v7.widget.RecyclerView
android:id="#+id/my_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:transcriptMode="normal">
</android.support.v7.widget.RecyclerView>
<!-- use this EditText box to call softKeyboard-->
<android.support.v7.widget.AppCompatEditText
android:id="#+id/cv_bottom_bar_edit"
style="#style/Widget.AppCompat.AutoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="18sp"
android:background="#color/colorPrimaryDark"
android:gravity="center"
/>
row.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F06060"
android:layout_margin="30dp"
android:padding="5dp"
android:textSize="25sp"
android:gravity="center"
>
MainActivity.java:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRecyclerView = findViewById(R.id.my_list);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
String[] myDataset = new String[]{"1", "2", "3","4","5","6","7","8","9"};
mAdapter = new MyAdapter(myDataset);
mRecyclerView.setAdapter(mAdapter);
}
Update:
I moved the windowFullscreen attribute from manifest to AppTheme because Android was not reading it from the manifest.
public class AndroidBug5497Workaround extends AppCompatActivity {
// For more information, see https://issuetracker.google.com/issues/36911528
// To use this class, simply invoke assistActivity() on an Activity that already has its content view set.
private ViewGroup contentContainer;
private ViewTreeObserver viewTreeObserver;
private Rect contentAreaOfWindowBounds = new Rect();
private LinearLayout.LayoutParams rootViewLayout; //-->change to the view root control type of your view.
private int usableHeightPrevious = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
contentContainer = findViewById(android.R.id.content);
rootViewLayout = (LinearLayout.LayoutParams) contentContainer.getLayoutParams();
}
#Override
protected void onPause() {
super.onPause();
if (viewTreeObserver.isAlive()) {
viewTreeObserver.removeOnGlobalLayoutListener(listener);
}
}
#Override
protected void onResume() {
super.onResume();
if (viewTreeObserver == null || !viewTreeObserver.isAlive()) {
viewTreeObserver = contentContainer.getViewTreeObserver();
}
viewTreeObserver.addOnGlobalLayoutListener(listener);
}
#Override
protected void onDestroy() {
super.onDestroy();
contentContainer = null;
viewTreeObserver = null;
}
ViewTreeObserver.OnGlobalLayoutListener listener = new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
contentContainer.getWindowVisibleDisplayFrame(contentAreaOfWindowBounds);
int usableHeightNow = contentAreaOfWindowBounds.height();
if (usableHeightNow != usableHeightPrevious) {
rootViewLayout.height = usableHeightNow;
contentContainer.layout(contentAreaOfWindowBounds.left, contentAreaOfWindowBounds.top, contentAreaOfWindowBounds.right, contentAreaOfWindowBounds.bottom);
contentContainer.requestLayout();
usableHeightPrevious = usableHeightNow;
}
}
};
}
Got it from facebook/react-native issue on github. Slight simplified for a common activity. Works good with portrait and landscape, from api 21, but it not much more tested than that. Use with care.
Notice this line:
((ViewGroup.MarginLayoutParams) view.getLayoutParams()).topMargin =
insets.getSystemWindowInsetTop();//what's the parent of "view"
According to getLayoutParams says, you should know what's the parent of "view" ,for example, if the parent is FrameLayout, then do like this:
((FrameLayout.LayoutParams) view.getLayoutParams()).topMargin =
insets.getSystemWindowInsetTop();
If the parent is relativelayout or linearlayout, also switch to definite type like above.
Edited: try this:
((WindowManager.LayoutParams) view.getLayoutParams()).topMargin =
insets.getSystemWindowInsetTop();
I am new bie in android.
Below is my senerio what i have and what i actually need.
I have one activity where i have declare one custom view which contains a set of button which click event display respective fragments.
This custom view will be appear on top of each fragment.
Now suppose on first button of custom view i am display fragment a fragment which display list-view..
on click on list-view it show another fragment i.e detail fragment
In detail fragment.. i have one button where i need to show an fragment overlay on main activity ... as on full screen.. how can i achive this?
In my opinion easiest way lead to this behavior is use Activity Overlay or DialogFragment. Example:
Activity Overlay
MainActivity.java
public class MainActivity extends AppCompatActivity
{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.buttonShow);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
}
});
}
}
MainActivity.xml
<RelativeLayout
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:id="#+id/mainLayout"
tools:context=".MainActivity"
android:background="#android:color/holo_orange_dark">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Main Activity"
android:textSize="30dp"
android:layout_centerInParent="true"/>
<Button
android:layout_width="150dp"
android:layout_height="50dp"
android:text="show"
android:id="#+id/buttonShow"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
SecondActivity.java
public class SecondActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
}
}
SecondActivity.xml
<RelativeLayout 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:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".SecondActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/holo_orange_light">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second Activity"
android:textSize="30dp"
android:layout_centerInParent="true"/>
</RelativeLayout>
</RelativeLayout>
Styles.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
</style>
<style name="TransparentFloatingActivity" parent="AppTheme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.arturszymanski.test" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:theme="#style/TransparentFloatingActivity"
android:name=".SecondActivity"
android:label="#string/title_activity_second" >
</activity>
</application>
</manifest>
DialogFragment
MyDialogFragment.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MyDialogFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/holo_orange_light">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FullScreen Fragment"
android:textSize="30dp"
android:layout_centerInParent="true"/>
</RelativeLayout>
MyDialogFragment.java
public class MyDialogFragment extends DialogFragment
{
private int margin;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
margin = 10;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_my_dialog, container, false);
}
#Override
public void onResume() {
int dialogHeight = MainActivity.displayMetrics.heightPixels - (margin * 2) - MainActivity.StatusBarHeight;
int dialogWidth = MainActivity.displayMetrics.widthPixels - (margin * 2);
getDialog().getWindow().setLayout(dialogWidth, dialogHeight);
super.onResume();
}
}
MainActivity.java
public class MainActivity extends AppCompatActivity
{
public static DisplayMetrics displayMetrics;
public static int StatusBarHeight;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
StatusBarHeight = getStatusBarHeight();
Button button = (Button) findViewById(R.id.buttonShow);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
MyDialogFragment dialogFragment = new MyDialogFragment();
dialogFragment.show(getFragmentManager(), "Dialog");
}
});
}
public int getStatusBarHeight() {
int result = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = getResources().getDimensionPixelSize(resourceId);
}
return result;
}
}
Other Files
Other files are the same as in example above.
If i follow your question than, You should use a RelativeLayout as overlay in main activity's layout. and set visibility according to your need.
layout_activity_main.xml
<RelativeLayout
android:width="match_parent"
android:height="match_parent">
<LinearLayout>
// your toolbar
// You fragment container
// your main layout goes here
</LinearLayout>
<RelativeLayout
android:id="#+id/overlay"
android:width="match_parent"
android:height="match_parent">
</RelativeLayout>
</RelativeLayout>
like this :
<LinearLayout id = "#+id/container">
<ToolBar id ="#+id/toolbar>
</ToolBar>
<FrameLayout id ="#+id/main_containt"/>
</LinearLayout>
getSupportFragmentManager().add(new Fragment(),R.id.container).commit();
use container as the container of fragment;
I have a question about xml parser in android. I am creating button information in the xml. I am getting its height,width,color and so on. I am creating all buttons in a function. Now i want to do the following. When i click the buttons, new android page opens. As far as i know i will do it by creating new activities.
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i=new Intent(MainActivity.this,MainActivity2.class);
startActivity(i);
}
});
I am writing this on my function which i create all buttons.when i do this it does not work.can somebody help me?
In your Activity :
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_main);
View btnTapOnMe = findViewById(R.id.btnTapOnMe);
btnTapOnMe.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(MainActivity.this,MainActivity2.class);
startActivity(i);
}
});
}
}
view_main.xml :
<RelativeLayout 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" >
<Button
android:id="#+id/btnTapOnMe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tap on Me" />
</RelativeLayout>
AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yourpackage"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name="com.yourpackage.MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.yourpackage.MainActivity2"/>
</application>
</manifest>
Should work like a charm
UPDATE:
Don't ever use AbsoluteLayout it is deprecated
This class was deprecated in API level 3.
Use FrameLayout, RelativeLayout or a custom layout instead.
First of all change it to Frame or Relative layout.
Here what i get in my example below :
public class MainActivity extends FragmentActivity {
public void AddAllButtons() {
AbsoluteLayout Layout = (AbsoluteLayout) findViewById(R.id.layout1);
Button btn = new Button(this);
btn.setText("Test case");
Layout.addView(btn);
AbsoluteLayout.LayoutParams absParams = (AbsoluteLayout.LayoutParams) btn.getLayoutParams();
absParams.x = 100;
absParams.y = 100;
absParams.width = 150;
btn.setLayoutParams(absParams);
btn.setBackgroundColor(Color.GREEN);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, SearchActivity.class);
startActivity(i);
}
});
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_main);
AddAllButtons();
}
}
and here is xml file :
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<Button
android:id="#+id/btnTapOnMe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tap on Me"/>
<AbsoluteLayout
android:id="#+id/layout1"
android:layout_below="#+id/btnTapOnMe"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</AbsoluteLayout>
</RelativeLayout>
I want to develop an Android application for a tablet in landscape mode with 2 fragments:
Fragment 1 contains a list of buttons.
Fragment 2 is a space for one the button-related fragments.
With "button-related fragments" I mean the following: When the user presses a button in fragment 1, a fragment associated with that button should be displayed in fragment 2.
Fragment 1 is kind of navigation panel.
In order to implement this, I wrote following code:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="mypackage.MainActivity"
android:label="#string/app_name"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".impl.activities.IntroActivity"></activity>
<activity android:name=".impl.activities.SimulationActivity"></activity>
</application>
MainActivity looks like this:
public class MainActivity extends Activity implements IMainActivity {
#Override
public void onCreate(final Bundle aSavedInstanceState) {
super.onCreate(aSavedInstanceState);
setContentView(R.layout.main);
}
#Override
public void show(final View aView, final Class<? extends Activity> aActivityClass) {
startActivity(new Intent(this, aActivityClass));
}
}
main.xml has following content:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:name="mypackage.fragments.ContentFragment"/>
ContentFragment looks like this:
public class ContentFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.mainfrag, container, false);
IMainActivity mainActivity = (IMainActivity) this.getActivity();
final IntroButtonClickListener introListener = new IntroButtonClickListener(
mainActivity, IntroActivity.class);
final IntroButtonClickListener simulationListener = new IntroButtonClickListener(
mainActivity, SimulationActivity.class);
view.findViewById(R.id.intro_button).setOnClickListener(introListener);
view.findViewById(R.id.simulation_button).setOnClickListener(simulationListener);
return view;
}
IntroButtonClickListener:
class IntroButtonClickListener implements View.OnClickListener {
private IMainActivity mainActivity;
private Class<? extends Activity> activityClass;
public IntroButtonClickListener(final IMainActivity aMainActivity,
final Class<? extends Activity> aActivityClass) {
this.mainActivity = aMainActivity;
this.activityClass = aActivityClass;
}
#Override
public void onClick(final View aView) {
this.mainActivity.show(aView, this.activityClass);
}
}
mainfrag.xml:
<?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">
<Button
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="25"
android:id="#+id/intro_button"
android:text="#string/intro_button"/>
<Button
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="25"
android:id="#+id/simulation_button"
android:text="#string/simulation_button"/>
<Button
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="25"
android:id="#+id/statistics_button"
android:text="#string/statistics_button"/>
<Button
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="25"
android:id="#+id/help_button"
android:text="#string/help_button"/>
</LinearLayout>
This code leads to following results:
When I launch the application, there are 4 buttons on the screen (from mainfrag.xml).
When I press intro_button or simulation_button, the view changes to IntroFragment or SimulationFragment, respectively.
When I press the Back button, the four buttons are visible again.
My problem: When IntroFragment or SimulationFragment get visible, the button panel disappears.
How should I modify my code such that both button panel and the respective "detail" view (IntroFragment, SimulationFragment) are visible at the same time (there is enough screen space for this) ?
This kind of example is shown in the APIDemos which are there in the Android SDK. where they have the left panel as listview and the selected item shows the related fragment in right side.
You can find that in
SDK\android-sdk_r11-windows\android-sdk-windows\samples\android-14\ApiDemos