I'm using Fragments in my app. One of them has a listView, and when I do a setOnItemClickListener, I want to pass the item clicked to the other fragment...
Here's the class OngletCours where I do my Intent:
l1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent a = new Intent(getActivity(), OngletNotes.class);
startActivity(a);
}
});
return rootView;
}
I'm getting the following error when I try to do an Intent to go to another Fragment:
E/AndroidRuntime: FATAL EXCEPTION: main
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.dasilvadd.students/com.example.dasilvadd.students.OngletNotes}; have you declared this activity in your AndroidManifest.xml?
Here is my Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="Student"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".PageAccueil">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Inscription"
android:label="Student" />
<activity
android:name=".Onglets"
android:label="Student"
android:theme="#style/AppTheme.NoActionBar" />
<activity android:name=".Reglages" />
<activity android:name=".MotDePasse" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
I've already tried to add it by myself, but it doesnt recognize the class I created for the Second Fragment (OngletNotes).
Please tell me how to solve this. And thank you in advance !
If you start OngletNotes using startActivity, I assume it's an Activity. In that case you need to add it to the AndroidManifest.xml
<activity
android:name=".OngletNotes"
android:label="Notes" />
If OngletNotes is a Fragment, it should be put inside of the Activity. You can't launch standalone Fragment without an Activity.
You need to create an Activity (don't forget to put it in AndroidManifest.xml)
Put your Fragment inside of the Activity (in xml or programmatically)
Start the Activity using startActivity
# Update: OngletNotes is a fragment
Fragment example:
public static OngletNotes newInstance(/* input parameters if any */) {
OngletNotes fragment = new OngletNotes();
// put values which you want to pass to fragment
// Bundle args = new Bundle();
// fragment.setArguments(args);
return fragment;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_ongletNotes, container, false);
// if you have passed some data above
// Bundle args = getArguments();
return view;
}
============================================================
# Update:
First, your onCreate in MainActivity,
// create a new instance of OngletCours (example is shown above)
OngletCours OngletCoursFragment = OngletCours.newInstance();
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_holder, OngletCoursFragment )
.commit();
// and your OnItemClickListener
l1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
OngletNotes targetFragment = OngletNotes.newInstance();
FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
transaction.addToBackStack(null);
transaction.replace(R.id.fragment_holder, targetFragment)
.commit();
}
});
activity_main.xml: you shoud have a FrameLayout which is used as a container to switch fragments
<FrameLayout
android:id="#+id/fragment_holder"
android:layout_width="match_parent"
android:layout_height="match_parent" />
After readed your last comment I have edited my aswer:
Open the fragment:
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
((MainActivity)getActivity()).setCurrentItem (1, true);
}
});
In your MainActivity which contains ViewPager For example private ViewPager mViewPager; you need setCurrentItem method:
public void setCurrentItem (int item, boolean smoothScroll) {
mViewPager.setCurrentItem(item, smoothScroll);
}
I suppose that OngleNotes fragment is the second fragment. That's why I send a 1 as a parameter.
Related
Hello, I do know that this is a duplicate question, but i was not able to find the solution from the other threads.
Here is my problem,
I have an app with bottom navigation bar with five fragment. I want to open the those fragment via the app shortcut.
Here what i have created,
shortcut.xml
<shortcuts xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="first"
android:enabled="true"
android:icon="#drawable/shortcut_1"
android:shortcutShortLabel="#string/shortcut_short_label_one"
android:shortcutLongLabel="#string/shortcut_long_label_one"
tools:targetApi="n_mr1">
<intent
android:action="com.xxxxxxx.xxxx.FIRST"
android:targetPackage="com.xxxxxxx.xxxx.test"
android:targetClass="com.xxxxxxx.xxxx.test.MainActivity" />
</shortcut>
<!-- Specify more shortcuts here. -->
<shortcut
android:shortcutId="second"
android:enabled="true"
android:icon="#drawable/shortcut_2"
android:shortcutShortLabel="#string/shortcut_short_label_two"
android:shortcutLongLabel="#string/shortcut_long_label_two"
tools:targetApi="n_mr1">
<intent
android:action="com.xxxxxxx.SECOND"
android:targetPackage="com.xxxxxxx.xxxx.test"
android:targetClass="com.xxxxxxx.xxxx.test.SecondFragment" />
</shortcut>
</shortcut>
Here is the onCreate() from the MainActivity
private static final String Second = "com.xxxxxxx.xxxx.SECOND";
//code vomited
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (Second.equals(getIntent().getAction())){
SecondFragment secondFragment = new SecondFragment();
android.support.v4.app.FragmentTransaction fragmentTransactionTwo = getSupportFragmentManager().beginTransaction();
fragmentTransactionTwo.replace(R.id.content_main, secondFragment, "Fragment two");
fragmentTransactionTwo.commit();
}
BottomNavigationView navigation = findViewById(R.id.navigation);
BottomNavigationViewHelper.disableShiftMode(navigation); //disabling the shitty shifting mode
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
FirstFragment firstFragment = new FirstFragment();
android.support.v4.app.FragmentTransaction fragmentTransactionOne = getSupportFragmentManager().beginTransaction();
fragmentTransactionOne.replace(R.id.content_main, firstFragment, "Fragment one");
fragmentTransactionOne.commit();
}
Here the first activty launches fine i.e MainActivity(). But Click on the second shortcut nothing happens.
Anyone explain me what am i doing wrong?
I see a couple of things that don't look right:
On shortcut.xml:
Both shortcuts should target the 'MainActivity' class, as this is the point of entry and the responsible for adding the fragments to the ui. So, you need to change the targetClass on the second shortcut and target the 'MainActivity' instead.
On the onCreate method:
When the action corresponds to the second shortcut, it sets the second fragment on the screen but the method goes on and sets the first fragment over it.
I guess it should be an if-else:
if (Second.equals(getIntent().getAction())) {
SecondFragment secondFragment = new SecondFragment();
android.support.v4.app.FragmentTransaction fragmentTransactionTwo = getSupportFragmentManager().beginTransaction();
fragmentTransactionTwo.replace(R.id.content_main, secondFragment, "fragment two");
fragmentTransactionTwo.commit();
} else {
FirstFragment firstFragment = new FirstFragment();
android.support.v4.app.FragmentTransaction fragmentTransactionOne = getSupportFragmentManager().beginTransaction();
fragmentTransactionOne.replace(R.id.content_main, firstFragment, "Fragment one");
fragmentTransactionOne.commit();
}
i have same problem like yours, i found how to move to fragment. you should hit the action. put this in onCreate, maybe this will help you
if ("com.xxxxxxx.YourShortcutAction".equals(getIntent().getAction())) {
val fragment = YourFragment()
addFragment(fragment)
}
im using kotlin for android
After some time I found the answer to how to open the fragment via the shortcut Kotlin:
shortcut.xml
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="mainShortcut"
android:enabled="true"
android:shortcutShortLabel="#string/somestring">
<intent
android:action="xxx.example.workapp.test"
android:targetPackage="xxx.example.workapp"
android:targetClass="xxx.example.workapp.MainActivity">
</intent>
</shortcut>
MainActivity
class MainActivity : AppCompatActivity() {
private lateinit var bottomNav : BottomNavigationView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
loadFragment(HomeFragment())
if ("xxx.example.workapp.test" == intent.action) {
loadFragment(YourFragment())
}
bottomNav = findViewById(R.id.bottomNav)
bottomNav.setOnItemSelectedListener {
when (it.itemId) {
R.id.homeFragment -> {
loadFragment(HomeFragment())
true
}
R.id.SettingsFragment -> {
loadFragment(SettingsFragment())
true
}
else -> {
false
}
}
}
}
private fun loadFragment(fragment: Fragment){
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.container,fragment)
transaction.addToBackStack(null)
transaction.commit()
}}
AndroidManifest.xml
...
<activity
android:name=".MainActivity"
android:configChanges="locale"
android:exported="true"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.shortcuts"
android:resource="#xml/shortcuts" />
</activity>
...
I want to ask for help.
I already created a list of activities in Android Studio.
Each Activity contains a specific item. Those items are different "Departments" in our University.
Example:
Activity 1 = College of Computer Studies;
Activity 2 = College of Teacher Education;
Activity 3 = College of Engineering.
My Spinner contains the departments.
My problem is, if I choose "College in Computer Science" in Spinner and click the "SEND" button, I want Activity 1 to be shown.
Would you help me with the code to do that?
**Spinner in activity_main.xml
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/spin"
android:entries="#array/punpDepartments"
android:layout_gravity="center_vertical">
</Spinner>
**These are the items in strings.xml
<string-array name="punpDepartments">
<item>College of Computer Studies</item>
<item>College of Business Education</item>
<item>College of Criminal Justice Education</item>
<item>College of Marine Education</item>
<item>College of Nursing</item>
<item>College of Pharmacy</item>
<item>College of Education</item>
**My code in Intent at MainActivity.java
public class MainActivity extends ActionBarActivity {
private static Button button_send;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OnClickButtonListener();
}
public void OnClickButtonListener(){
button_send = (Button) findViewById(R.id.button);
button_send.setOnClickListener(
new View.OnClickListener(){
#Override
public void onClick(View v){
Intent intent = new Intent("com.example.imelda.mythesis.ListActivity");
startActivity(intent);
}
}
);
}
**Extends in ListActivity.java
public class ListActivity extends ActionBarActivity {
private static Button button_next;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
OnClickButtonListener();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_list, menu);
return true;
}
public void OnClickButtonListener() {
button_next = (Button) findViewById(R.id.button4);
button_next.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("com.example.imelda.mythesis.SecondList");
startActivity(intent);
}
}
);
}
**I have also added this in AndroidManifest.xml enter code here
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.imelda.mythesis" >
<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" >
<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:name=".ListActivity"
android:label="#string/title_activity_list" >
<intent-filter>
<action android:name="com.example.imelda.mythesis.ListActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
first get your spinner in the main class like this
Spinner spin =(Spinner)findViewById(R.id.spin);
now in your on click method do this
int position =spin.getSelectedItemPosition();
//change the activities with yours
switch (position){
case 0: intent.setClass(Activity1.class,MainActivity.this);
break;
case 1: intent.setClass(Activity2.class,MainActivity.this);
break;
case 2: intent.setClass(Activity3.class,MainActivity.this);
break;
case 3: intent.setClass(Activity4.class,MainActivity.this);
break;
case 4: intent.setClass(Activity5.class,MainActivity.this);
break;
}
startActivity(intent);
I don't know what I'm making wrong, but my App crash when I launch. I want to implement Tab bar list with FragmentActivity.
I really need help :(
The error returned is :
Unable to start activity ComponentInfo
Caused by: java.lang.NullPointerException
at jardelcompany.bundoransurfco.MainActivity.onCreate(MainActivity.java:79)
(line 79 is actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);)
MainActivity.java :
public class MainActivity extends FragmentActivity implements
ActionBar.TabListener {
SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
mSectionsPagerAdapter = new SectionsPagerAdapter(this,
getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager
.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
#Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
actionBar.addTab(actionBar.newTab()
.setText(mSectionsPagerAdapter.getPageTitle(i))
.setTabListener(this));
}
activity_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"
tools:context=".MainActivity"
android:id="#+id/mainLayout"
android:background="#FFFFFF"> />
<view
android:layout_width="match_parent"
android:layout_height="match_parent"
class="android.support.v4.view.ViewPager"
android:id="#+id/pager"/>
</RelativeLayout>
I use SectionsPagerAdapter for FragmentPageAdapter
SectionsPagerAdapter.java:
public class SectionsPagerAdapter extends FragmentPagerAdapter {
protected Context mContext;
public SectionsPagerAdapter(Context context, FragmentManager fm) {
super(fm);
mContext = context;
}
#Override
public Fragment getItem(int position) {
switch(position) {
case 0:
return new FirstFragment();
case 1:
return new LoginFragment();
}
return null;
}
#Override
public int getCount() {
return 2;
}
#Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return mContext.getString(R.string.title_section1).toUpperCase(l);
case 1:
return mContext.getString(R.string.title_section2).toUpperCase(l);
}
return null;
}
}
FirstFragment.java:
public class FirstFragment extends ListFragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_main,
container, false);
return rootView;
}
}
LoginFragment.java :
public class LoginFragment extends ListFragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_login,
container, false);
return rootView;
}
}
Here is my AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jardelcompany.bundoransurfco" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" /> <!-- To retrieve the account name (email) as part of sign-in: -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> <!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<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"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:label="#string/title_activity_login"
android:parentActivityName=".MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize|stateVisible" >
</activity>
</application>
</manifest>
And my styles.xml :
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
Remove this code into separate method like:
private void initUI(){
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
mSectionsPagerAdapter = new SectionsPagerAdapter(this,
getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager
.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
#Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
actionBar.addTab(actionBar.newTab()
.setText(mSectionsPagerAdapter.getPageTitle(i))
.setTabListener(this));
}
}
and call this method from onResume() instead of onCreate(). Also you are using getActionBar() and same time getSupportFragmentManager() maybe you should use getSupportActionBar()? What is the min API level of your project?
Try adding this line of code to your manifest file
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="14" />
I have searched around but none of the solutions worked for my specific case. If I add
QuickContactBadge contactBadge = (QuickContactBadge) findViewById(R.id.quickContactBadge);
I it crashes. Then I changed it to:
QuickContactBadge contactBadge;
protected void onCreate(Bundle savedInstanceState) {
...
contactBadge = (QuickContactBadge) findViewById(R.id.quickContactBadge);
}
And it doesn't crash. But if I add contactBadge.Anything(); it crashes. No matter what
method it crashes. I.E. contactBadge.assignContactFromEmail("foo#foo.com", true);
Android Activity:
public class MainActivity extends Activity {
QuickContactBadge contactBadge;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction().add(R.id.container, new MainFragment()).commit();
}
contactBadge = (QuickContactBadge) findViewById(R.id.quickContactBadge);
contactBadge.assignContactFromEmail("pointlightproductions.net#gmail.com", true);
}
public static class MainFragment extends Fragment {
public MainFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pointlight.android.kingdomcraft"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/android:Theme.Holo.NoActionBar" >
<activity
android:name="com.pointlight.android.kingdomcraft.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>
</application>
</manifest>
Layout:
<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"
tools:context="com.pointlight.android.kingdomcraft.MainActivity$MainFragment" >
<QuickContactBadge
android:id="#+id/quickContactBadge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
First method: You're calling findViewById() when the activity is instantiated and its member variables are initialized. The activity won't have a Window yet and it will NPE. Call findViewById() only in onCreate() or later, after setContentView().
Second method: You don't have setContentView() with a view hierarchy that has a view with the given id. null is returned and invoking method on it will NPE.
From the code you later added, it seems the view is in your fragment layout and not the activity layout. It won't be a part of the activity view hierarchy in onCreate(). You should move the code to the fragment's onCreateView() instead:
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
contactBadge = (QuickContactBadge) rootView.findViewById(R.id.quickContactBadge);
contactBadge.assignContactFromEmail("pointlightproductions.net#gmail.com", true);
I have a simple Activity that uses a android:theme="#android:style/Theme.Dialog" in the manifest.
My activity consists of an EditText, 2 Buttons, and a TextView. It is nothing more than a box for the user to enter in a name and press OK/Cancel.
I just want to focus the EditText and have the soft keyboard automatically show when the Activity is started. I've read countless posts about this but I just can't seem to get it to work. When the activity starts the blinking cursor appears in the EditText, but the keyboard won't show until I click inside it.
Here is my Activity:
public class Finalize extends Activity {
private EditText mEditName;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.finalize_dialog);
mEditName = (EditText) findViewById(R.id.file_name_edit);
mEditName.setFocusable(true);
mEditName.requestFocus();
mEditName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
});
}
}
I've also tried this in onCreate:
InputMethodManager mgr = (InputMethodManager) getSystemService(this.INPUT_METHOD_SERVICE);
mgr.showSoftInput(mEditName, 0);
Edit: My manifest for reference
<activity class=".Finalize"
android:name=".Finalize"
android:label="#string/file_name_title"
android:theme="#android:style/Theme.Dialog"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysVisible">
</activity>
The following should work. Go to your manifest and update your activity line with the android:windowSoftInputMode attribute.
<activity android:name=".Finalize"
android:windowSoftInputMode="stateAlwaysVisible">
...
</activity>
See the following documentation page for more details on the different parameters that can be passed into this attribute.
I tested the above and it works fine for me. Here is my terribly simple example.
Code:
public class DialogActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
<EditText android:id="#+id/edit_text_test"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Manifest:
<activity android:name=".DialogActivity"
android:windowSoftInputMode="stateAlwaysVisible"
android:label="#string/app_name"
android:theme="#android:style/Theme.Dialog">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Try this its work for me
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);