android-activity

How to send data from fragment to activity [duplicate]

痞子三分冷 提交于 2019-12-30 05:29:11
问题 This question already has answers here : Passing data between a fragment and its container activity (13 answers) Closed 2 years ago . In my application I have two fragments in an activity. In one of the fragments I have data, such as : String name = "Transporter"; I want send this name to container activity. How can I do it? Please help me. 回答1: The fragment will be attached to the activity which you launch from. Thus, you can create a callback method in your activity which can be called from

How to navigate to a parent activity

余生长醉 提交于 2019-12-30 04:11:26
问题 Well when im working on something and i need to configure the action bar in my app i started from the http://developer.android.com and i found what i am looking for public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { // Respond to the action bar's Up/Home button case android.R.id.home: NavUtils.navigateUpFromSameTask(this); return true; } return super.onOptionsItemSelected(item);} ofcourse after adding the <activity android:name="com.example.myfirstapp

Android start activity on Menu Item selection

吃可爱长大的小学妹 提交于 2019-12-30 03:09:15
问题 I have 2 classes. One will be a basic instructions screen and on that screen it will have a menu that will let you go to the other class. The other class is a MapActivity. I believe the problem is that its not finding the other class. I've tried a few different ways of declaring the intent to find the class. This is the latest thing I've tried: @Override public boolean onCreateOptionsMenu(Menu menu){ MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.mainmenu, menu); return

When is View.onMeasure() called?

孤街浪徒 提交于 2019-12-30 02:37:10
问题 When is View.onMeasure(int widthMeasureSpec, int heightMeasureSpec) called? I have an Activity that needs to perform an action after onMeasure has been called. My question is the same as the unanswered question posted here. The View documentation states that onMeasure is called when requestLayout() is called, which is apparently called by a view on itself when it believes that is can no longer fit within its current bounds. However, this doesn't tell me when my activity can assume that my

Call startActivityForResult from Fragment doesn't call onActivityResult

半城伤御伤魂 提交于 2019-12-30 01:57:05
问题 I have a DialogActivity which is called from a Fragment for show a custom Dialog with two image buttons. In DialogActivity.onCreate final Dialog dialog = new Dialog(this, R.style.DialogTheme); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.dialog_pause); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); dialog.show(); In DialogActivity.onClick @Override public void onClick(View v) { Log.d(LOGTAG, "onClick

retrofit 2.0 how to print the full json response?

◇◆丶佛笑我妖孽 提交于 2019-12-30 01:34:05
问题 I am moving from Volley to Retrofit currently version 2.0. How to print the the full json response code ? includes : compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2' compile 'com.squareup.retrofit:retrofit:2.0.0-beta2' RestClient : OkHttpClient client = new OkHttpClient(); client.interceptors().add(new Interceptor() { @Override public Response intercept(Interceptor.Chain chain) throws IOException { Response response = chain.proceed(chain.request()); return response; } }); Gson gson

Android Show Soft Keyboard When First Activity Starts?

拈花ヽ惹草 提交于 2019-12-30 01:24:10
问题 I need to display the virtual keyboard when the application starts, but so far I've failed. I use this code in method "OnCreate"to display the virtual keyboard InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(txtBuscar.getId(), InputMethodManager.SHOW_FORCED); this code works fine on any screen at any time, but does not work when the "first" activity begins. Why? I tried it when I start another activity and it works, but does not

How to auto scroll up Recycler view in Android?

痴心易碎 提交于 2019-12-30 00:59:08
问题 I have developed some chat application where i can send and received messages. But the problem is whenever i send or receive messages the recycler view is not scrolling to top so that messages gets diplayed above the keypad. I have used the above mentioned recycler view android.support.v7.widget.RecyclerView . 回答1: On updating recyclerview try to run this code : recyclerView.post(new Runnable() { @Override public void run() { // Call smooth scroll recyclerView.smoothScrollToPosition(adapter

Using Non-Production Activity for Testing with Android Studio

不想你离开。 提交于 2019-12-30 00:31:05
问题 Before Android Studio, testing and Android app involved a separate Android project that would be ignored when building for production. With Android Studio, production code and test code exist within the same project, which itself only has one set of anything else (manifest, assets, resources). This being the case, how would I define a custom Activity to be used only for testing? For Android to allow any Activity to be started, it must be declared in the manifest. Is there a way around this

Testing that button starts an Activity with Robolectric

删除回忆录丶 提交于 2019-12-29 18:44:12
问题 Hi I have the following code: @RunWith(Test9Runner.class) public class MainActivityTest { private MainActivity activity; private Button pressMeButton; @Before public void setUp() throws Exception { activity = new MainActivity(); activity.onCreate(null); pressMeButton = (Button) activity.findViewById(R.id.button1); } @Test public void shouldUpdateResultsWhenButtonIsClicked() throws Exception { pressMeButton.performClick(); ShadowActivity shadowActivity = shadowOf(activity); Intent intent =