I want to parse a String (link) to another activity, when a button in a ListView is clicked.
The ListView ist populated by JSON (fetched MySQL-Data).
What's the trick to send the 'link' to the other activity, when I press a button in the ListView?
So far I tried searching for XML Form submit... but I think this is not the right way, I think to much in the direction of programming html forms...
my ListView (populated dynamically)
<TextView
android:id="#+id/link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="82dp"
android:layout_marginLeft="82dp"
android:layout_marginTop="33dp"
android:textSize="18dp"
android:text=""
android:textColor="#color/colorAccent"
android:textStyle="bold"
android:visibility="invisible"/>
<android.support.v7.widget.AppCompatImageButton
android:id="#+id/videobutton"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_gravity="start"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:background="#drawable/cerclebackgroundpurple"
android:padding="10dp"
android:src="#drawable/ic_play"
android:tint="#color/colorPrimary" />
What I now want to do is to get the populated 'link' from the TextView in my new activity.
May be you are clicking a list item and navigate to another activity with required String(link) as you explained. For this purpose, try this.
On list item click, call activity intent like
Intent i=new Intent(CurrentActivity.this,NextActivity.class);
i.putExtra("link","PUT YOUR LINK HERE");
startActivity(i);
Related
I have list of item, i am using HorizontalGridView to display that item, i want to keep the HorizontalGridView in center of the screen but its not working.
Following is my code:
<android.support.v17.leanback.widget.HorizontalGridView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_centerHorizontal="true"/>
But it occupies complete width and height even-though there is less item
Note: I am developing for android tv using leanback library
It's better to use RecyclerView if you want to center and wrap content. Actually, HorizontalGridView extends RecyclerView, so it will be easy to change to:
<androidx.recyclerview.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_centerHorizontal="true"/>
I am new to Android app development and using Android studio. I want to place a Textview in ToolBar. Here is my code of ToolBar xml file:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF5722"
android:elevation="4dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Holler"
android:textColor="#android:color/white"
android:textStyle="bold|italic"
android:textSize="30dp"
android:layout_gravity="center"
android:id="#+id/toolbar_title"
android:gravity="center"
/>
</android.support.v7.widget.Toolbar>
On my first activity it is showing as expected in centre. But when I launch new Activity the TextView is moving to bit right. Here is my code for FirstActivity:
toolbarHome = (Toolbar) findViewById(R.id.tool_bar_home); // Attaching the layout to the toolbar object
setSupportActionBar(toolbarHome);
final android.support.v7.app.ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setHomeAsUpIndicator(R.mipmap.ic_launcher);
actionBar.setDisplayHomeAsUpEnabled(true);
}
Please let me know if you require more code.
It is the default behaviour of toolbar. It is because of the margins of the back button. If it is a simple text, you can use the toolbar title to set a textview.
But if you want to use your textview in the toolbar. You want to hide the back button by calling :
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
Now you have to create your own back button by setting a ImageButton/ImageView with back arrow icon in the layout file along with your TextView to achieve the desired results.
I'm trying to use a spinner view element in my android application, but the dropdown arrow always goes out of the element box.
Code from layout file:
<Spinner
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="#+id/spinner1"
android:layout_toRightOf="#+id/text1"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:spinnerMode="dropdown" />
And Here is the cropped output:
I dont use any mode.
May be that is the problem.
My project also uses Xamarin with MvvmCross, but I don't think this will effect the answer since the problem is all view-layout/axml related.
I have a GridView that summarizes a list of contacts. When clicking on this grid view, I would like the user to be taken to another screen to add more contacts to this list (so there is more space).
Subscribing to the GridView's OnClick event gives me an exception, saying I should be subscribing to the item click event, so I have done this using a clickable relative layout that surrounds the GridView (and its accompanying empty image view) as such:
...
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/addContactsRelativeLayout"
android:clickable="true">
<ImageView
android:id="#+id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/ic_add" />
<Mvx.MvxGridView
android:id="#+id/addContactsGridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
local:MvxBind="ItemsSource Contacts"
local:MvxItemTemplate="#layout/contact_summary_item"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:columnWidth="55dip"
android:gravity="center" />
</RelativeLayout>
...
This works fine when the GridView is empty, and the empty ImageView is shown. However, when there are items in the GridView, the RelativeLayout no longer seems to exist and clicks over the GridView can be seen to highlight items on the GridView. This means the user is not taken to the screen to edit their contact list.
I have tried several different configurations and attributes from similar questions on SO, but I think the addition of an empty view is causing problems. Any help would be greatly appreciated.
Ok, after a lot more playing around I found a solution.
Essentially it's adding another relative layout, higher in the z-index and therefore above the 'real' contents, within the surrounding relative layout.
...
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<ImageView
android:id="#+id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/ic_add" />
<Mvx.MvxGridView
android:id="#+id/addContactsGridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
local:MvxBind="ItemsSource Contacts"
local:MvxItemTemplate="#layout/contact_summary_item"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:columnWidth="55dip"
android:gravity="center"
android:focusable="false"/>
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:clickable="true"
android:id="#+id/addContactsRelativeLayout"/>
...
Then just move all your click listeners to listen to the relative layout at the bottom.
I am trying to achieve a log-in screen like the following:
Where the field's name is displayed in the field itself. I am using the ADT plugin in Eclipse. I tried setting the android:text attribute of the text input, but I don't think this is correct because through the password field, only the dots show (the redacted text), and not the text itself. What is the attribute then. I have looked in the documentation for the EditText widget.
The XML I currently have for the two EditText fields are:
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="#+id/editText1" android:inputType="textEmailAddress" android:text="#string/username">
<requestFocus></requestFocus>
</EditText>
<EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="#+id/editText2" android:inputType="textPassword" android:text="#string/password" ></EditText>
You should be able to set default values for the fields with android:hint or android:sethint I think its the first.
android:hint="Please enter your password"
its the first one, thanks to a search on SO. Just for additional info it came up with this.
SO Question about android:hint
Share Java code for when click on Submit Button then Show the Name
<EditText
android:id="#+id/name_enter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/Name"
android:inputType="textCapSentences|textAutoCorrect"
/>