There is the following code:
mListOfExistedMessages.setAdapter(new ExistedTasksExpandableListAdapter(context, persons));
mListOfExistedMessages.setOnChildClickListener(new OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView parent,
View v, int groupPosition, int childPosition,
long id) {
Toast.makeText(ExistedMessagesActivity.this, "1",
Toast.LENGTH_LONG).show();
return false;
}
});
mListOfExistedMessages.setItemsCanFocus(false);
ExistedTasksExpandableListAdapter is my custom adapter, and code of adapter works good (shows custom views for group and child). Code of child layout:
<?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:focusable="false"
android:orientation="horizontal"
android:padding="10dip"
android:paddingLeft="15dip" >
<CheckBox
android:id="#+id/listItemExistedMessageChecked"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center"
android:text="" />
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1.7"
android:focusable="false"
android:focusableInTouchMode="false"
android:orientation="vertical" >
<TextView
android:id="#+id/listItemExistedMessageText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:focusable="false"
android:focusableInTouchMode="false"
android:maxLines="2"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/listItemExistedMessageRepeating"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="italic" />
</LinearLayout>
<View
android:layout_width="5dip"
android:layout_height="match_parent"
android:layout_marginLeft="5dip"
android:background="#1874CD"
android:focusable="false"
android:focusableInTouchMode="false" />
<LinearLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Next event:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<TextView
android:id="#+id/listItemExistedMessageDateTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
But there is no messages by child view clicking! How can I fix it?
Try to add:
return super.onChildClick(parent, v, groupPosition, childPosition, id);
instead of false. Did this work for you?
Related
I have two radiobutton groups that need to be initialized when loading the screen, so I used this code:
mVisibilityPublic.setChecked(true);
But when I load the screen I get the following (first is the wrong behavior, second is the expected one):
I've tried with all these:
mVisibilityPublic.setSelected(true);
mVisibilityPublic.performClick();
mVisibilityPublic.setActivated(true);
mVisibilityPublic.invalidate();
mVisibilityPublic.requestLayout();
But I get the same result.
<ScrollView 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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:orientation="vertical"
android:padding="#dimen/form_vertical_spacing"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".createevent.CreateEventActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="#string/create_event_privacy"
android:textColor="#color/colorAccent"
android:textStyle="bold"
/>
<RadioGroup
android:id="#+id/create_visibility_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingTop="16dp">
<RadioButton
android:id="#+id/createevent_visibility_public"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_public_event"/>
<RadioButton
android:id="#+id/createevent_visibility_private"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_private_event"/>
<RadioButton
android:id="#+id/createevent_visibility_ppv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_ppv"/>
</RadioGroup>
<LinearLayout
android:id="#+id/ppv_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="#string/create_event_ppv_section"
android:textColor="#color/colorAccent"
android:textStyle="bold"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:id="#+id/ppv.currency.layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<com.myapp.ui.AutoCompleteCombo
android:id="#+id/ppv.currency"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/create_event_ppv_currency">
</com.myapp.ui.AutoCompleteCombo>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/ppv.price.layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_weight="1">
<android.support.design.widget.TextInputEditText
android:id="#+id/ppv.price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/create_event_ppv_price"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:maxLines="1"
/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<RadioGroup
android:id="#+id/ppv_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingTop="16dp">
<RadioButton
android:id="#+id/ppv_all"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_ppv_allcountries"/>
<RadioButton
android:id="#+id/ppv_allexcept"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_ppv_except"/>
<RadioButton
android:id="#+id/ppv_only"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_ppv_some"/>
</RadioGroup>
<com.myapp.countries.CountriesMultiCombo
android:id="#+id/create.ppv.countrylist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
/>
</LinearLayout>
<View
android:id="#+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/general_info"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:layout_marginLeft="-32dp"
android:layout_marginRight="-32dp"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:background="#color/colorDivider"
/>
<LinearLayout
android:id="#+id/geoblock_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="#string/geo_blocking_settings_title"
android:textColor="#color/colorAccent"
android:textStyle="bold"
/>
<RadioGroup
android:id="#+id/geo_radiogroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingTop="16dp">
<RadioButton
android:id="#+id/geo_none"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/geo_none"/>
<RadioButton
android:id="#+id/geo_blockonly"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/geo_block_only"/>
<RadioButton
android:id="#+id/geo_blockexcept"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/geo_block_all_except"/>
</RadioGroup>
<com.myapp.createevent.countries.CountriesMultiCombo
android:id="#+id/create.geo.countrylist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
/>
</LinearLayout> <Button
android:id="#+id/test_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CLICK ME"/>
</LinearLayout>
</ScrollView>
Note that if I select the option manually (like I did with the second example in the image) I get the proper result. Its only if I do it programmatically that its missing the inner circle.
public class TestFragment extends Fragment {
private Unbinder mUnbinder;
#BindView(R.id.createevent_visibility_public)
RadioButton mVisibilityPublic;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View inflate = inflater.inflate(R.layout.fragment_advanced_opts, container, false);
mUnbinder = ButterKnife.bind(this, inflate);
return inflate;
}
public static TestFragment newInstance(int tvId, int eventId) {
TestFragment testFragment = new TestFragment();
Bundle args = new Bundle();
args.putInt(TV_ARGUMENT, tvId);
args.putInt(EVENTID_ARGUMENT, eventId);
testFragment.setArguments(args);
return testFragment;
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mVisibilityPublic.setChecked(true);
}
}
i have spinner and 3 item video and photo and text and 4 button how i can show button if spinner select :
0
dow
favorite
Im trying to show a hidden button with spinner click
this is the cod
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="#+id/activity_secim"
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="com.example.rdvanayan.yeni.Secim"
android:background="#android:color/holo_green_light">
<TextView
android:text="Bir seçim yapınız"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:textSize="20dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#000000"
android:background="#ffffff"
/>
<Button
android:text="KAYDET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/kad1"
android:textStyle="normal|bold|italic"
android:textSize="18sp"
android:layout_marginTop="22dp"
android:layout_below="#+id/editText7"
android:layout_alignParentRight="true"
android:visibility="invisible"
android:layout_alignParentEnd="true" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner"
android:layout_marginTop="12dp"
android:layout_below="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_below="#+id/kad1"
android:weightSum="1"
android:id="#+id/linearLayout2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/camera1"
android:layout_width="110dp"
android:layout_height="78dp"
android:layout_marginRight="100dp"
android:scaleType="centerInside"
android:visibility="invisible"
app:srcCompat="#drawable/camera" />
<ImageButton
android:layout_width="111dp"
android:layout_height="78dp"
app:srcCompat="#drawable/galll"
android:id="#+id/imageButton9"
android:scaleType="centerInside"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:visibility="invisible"
android:layout_alignParentEnd="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="URL İNDİR "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button5"
android:layout_below="#+id/imageButton9"
android:layout_alignParentRight="true"
android:visibility="invisible"
android:layout_alignParentEnd="true" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp">
<ImageButton
android:id="#+id/imageButton11"
android:layout_width="wrap_content"
android:layout_height="78dp"
android:visibility="invisible"
android:layout_marginRight="90dp"
android:onClick="dispatchTakeVideoIntent"
android:scaleType="centerInside"
app:srcCompat="#drawable/video_kamera" />
<ImageButton
android:layout_width="111dp"
android:layout_height="78dp"
app:srcCompat="#drawable/video_galeri"
android:id="#+id/imageButton12"
android:scaleType="centerInside"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:visibility="invisible"
android:layout_alignParentEnd="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="URL İNDİR "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button4"
android:layout_below="#+id/imageButton9"
android:layout_alignParentRight="true"
android:visibility="invisible"
android:layout_alignParentEnd="true" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/editText7"
android:hint="BAŞLIK"
android:visibility="invisible"
android:textStyle="normal|bold|italic"
android:textSize="20sp"
android:layout_below="#+id/spinner"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#000000"
android:background="#ffffff"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/editText8"
android:textSize="20dp"
android:hint="AÇIKLAMA"
android:textStyle="normal|bold|italic"
android:textColor="#000000"
android:background="#ffffff"
android:layout_below="#+id/editText7"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:visibility="invisible"
android:layout_marginTop="11dp" />
<ImageView
android:id="#+id/igm"
android:layout_width="50dp"
android:layout_height="32dp"
app:srcCompat="#drawable/son"
android:layout_below="#+id/editText8"
android:layout_alignRight="#+id/editText8"
android:layout_alignEnd="#+id/editText8"
android:layout_marginRight="55dp"
android:layout_marginEnd="55dp" />
</RelativeLayout>
and this is spinner item
<string-array name="secim">
<item> YAZI </item>
<item> RESİM </item>
<item> VİDEO </item>
</string-array>
Any help would be appreciated.
You have to show and hide buttons on spinner selection in your Activity class. Set "OnItemSelectedListener" to your spinner, it will override few methods. In overridden "OnItemSelected" method hide the button like this:
yourButton.setVisibility(VISIBILTY.GONE);
I would like to add the previous answer as a comment. But the reputation is inadequate.
Actually it should be like this:
Use for hide: resimButonu.setVisibility(View.GONE);
or resimButonu.setVisibility(INVISIBLE);
use for show: resimButonu.setVisibility(View.VISIBLE); or resimButonu.setVisibility(VISIBLE);
thanks but i have 4 button and text i need :
if RESİM selected show 2 button
if * YAZI * selected show textbox
if *VİDEO * selected show 2 button
i have 4 button in app
ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.secim, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
camerax.setVisibility(View.VISIBLE);
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
I'm making a football league app, and i need to show the classification.
I'm trying to show a header that indicates what represents each field and a listview with the teams below.
I'm using a SimpleCursorAdapter to fill the list, but if the values have a different number of digits the list is misaligned. ¿How can i align it or at least add a 0 before the one-digit numbers with the adapter?
The soure code of the fragment and the xml:
ClassificacioFragment.java:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
String[] from = { EquipsContract.EquipEntry.COLUMN_NAME_NOM,
EquipsContract.EquipEntry.COLUMN_NAME_VICTORIES, EquipsContract.EquipEntry.COLUMN_NAME_DERROTES,
EquipsContract.EquipEntry.COLUMN_NAME_EMPATS, EquipsContract.EquipEntry.COLUMN_NAME_PUNTS};
int[] to = {R.id.item_nom, R.id.item_victories, R.id.item_derrotes, R.id.item_empats, R.id.item_punts};
View rootview = inflater.inflate(R.layout.fragment_classificacio, container, false);
ListView listView = (ListView) rootview.findViewById(R.id.classificacio);
listView.invalidateViews();
SimpleCursorAdapter adapter = new SimpleCursorAdapter(rootview.getContext(), R.layout.equip_row,
DBHandler.getDbInstance(getContext()).cursorClassificacio(), from, to);
listView.setAdapter(adapter);
String size = Integer.toString(DBHandler.getDbInstance(getContext()).getAllEquips().size());
Toast toast = Toast.makeText(getContext(), size, Toast.LENGTH_LONG);
toast.show();
return rootview;
}
fragment XML:
<FrameLayout 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="idi.francesc.footballleague.ClassificacioFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/header_classificacio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="#string/header_equip"
android:textSize="18sp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginStart="28dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="#string/header_victories"
android:textSize="18sp"
android:layout_alignParentTop="true"
android:layout_toStartOf="#+id/header_d"
android:layout_marginEnd="30dp"
/>
<TextView
android:id="#+id/header_d"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="#string/header_derrotes"
android:textSize="18sp"
android:layout_alignParentTop="true"
android:layout_toStartOf="#+id/header_e"
android:layout_marginEnd="27dp"
/>
<TextView
android:id="#+id/header_e"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="#string/header_empats"
android:textSize="18sp"
android:layout_alignParentTop="true"
android:layout_toStartOf="#+id/header_p"
android:layout_marginEnd="38dp"
/>
<TextView
android:id="#+id/header_p"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="#string/header_punts"
android:textSize="18sp"
android:layout_marginEnd="12dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
<ListView
android:id="#+id/classificacio"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/header_classificacio">
</ListView>
</RelativeLayout>
</FrameLayout>
Listview Row:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/item_nom"
android:layout_width="wrap_content"
android:layout_height="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:textSize="20sp"
android:padding="2dp"
android:layout_marginStart="10dp"
android:text="F.C. Barcelona"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="?android:attr/listPreferredItemHeight"
android:id="#+id/item_victories"
android:padding="2dp"
android:textSize="15sp"
android:text="10"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_toStartOf="#+id/item_derrotes"
android:layout_marginEnd="25dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="?android:attr/listPreferredItemHeight"
android:id="#+id/item_derrotes"
android:padding="2dp"
android:textSize="15sp"
android:text="20"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_toStartOf="#+id/item_empats"
android:layout_marginEnd="25dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="?android:attr/listPreferredItemHeight"
android:id="#+id/item_empats"
android:padding="2dp"
android:textSize="15sp"
android:text="30"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_toStartOf="#+id/item_punts"
android:layout_marginEnd="25dp"/>
<TextView
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_width="wrap_content"
android:id="#+id/item_punts"
android:padding="6dp"
android:textSize="18sp"
android:text="40"
android:gravity="center_vertical"
android:layout_marginEnd="2dp"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
And this is the result:
thanks.
You can simplify your ListView Row to use LinearLayout with weight parameters. It's more efficient and prevents issues with TextView's floating width.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="9">
<TextView
android:id="#+id/item_nom"
android:layout_width="0dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:textSize="20sp"
android:padding="2dp"
android:layout_marginStart="10dp"
android:layout_weight="4"
android:text="F.C. Barcelona"/>
<TextView
android:layout_width="0dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_weight="1"
android:id="#+id/item_victories"
android:textSize="15sp"
android:text="10"
android:gravity="center"/>
<TextView
android:layout_width="0dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_weight="1"
android:id="#+id/item_derrotes"
android:textSize="15sp"
android:text="20"
android:gravity="center"/>
<TextView
android:layout_width="0dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_weight="1"
android:id="#+id/item_empats"
android:textSize="15sp"
android:text="30"
android:gravity="center"/>
<TextView
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_width="0dp"
android:layout_weight="2"
android:id="#+id/item_punts"
android:textSize="18sp"
android:text="40"
android:gravity="center"/>
</LinearLayout>
At first all of your text in the TextView must be center aligned.
android:gravity="center"
Then, pogramatically you should find the largest TextView and set the width of each other TextView in that row.
Or you use TableLayout ;)
Create a function for appending 0 with numbers less than 10.
public String appendZero(int input) {
if (input >= 10) {
return String.valueOf(input);
} else {
return "0" + String.valueOf(input);
}
}
While setting the text, call like this :
item_victories.setText(appendZero(victory_count.get(position)));
Hope this one will works for you.
I have an activity in which I have inflated another layout. OnClick of next destination I am getting inflated a new layout. Now I want to remove the inflated layout. So I want to access the linear layout of remove from inside inflated layout. How can I access this??
Layout looks like this :
I have achieved to inflate layout and remove the first destination from parent which is a part of parent layout. Now I want to do same with inflated destination layout. onClick of remove the inflated layout should get removed.
Next_destination layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_weight="1.00"
android:background="#android:color/white"
android:id="#+id/LinearAddedDestination">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="DESTINATION"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="40dp"
android:orientation="horizontal"
android:background="#drawable/shape"
android:gravity="right"
android:layout_gravity="center|right"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="80dp"
android:id="#+id/remove">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_clear_black_18dp"
android:layout_marginLeft="05dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="REMOVE"
android:layout_gravity="center"
android:layout_marginLeft="05dp"
android:textSize="14sp"
android:layout_marginRight="15dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="08dp"
android:background="#drawable/line2"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:background="#drawable/ic_place_black_48dp"
android:layout_marginTop="05dp"
android:layout_gravity="center" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/ic_chevron_right_black_24dp"
android:layout_marginEnd="10dp"
android:text="#string/Loc"
android:layout_gravity="center"
android:layout_marginTop="05dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:cursorVisible="false"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Street/Building/Place"
android:layout_marginStart="48dp"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:background="#drawable/ic_description_black_48dp"
android:layout_marginTop="10dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginEnd="10dp"
android:hint="#string/LocationDetails"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_marginStart="48dp"
android:hint="#string/HouseDetails" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:background="#drawable/ic_person_black_48dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:text="#string/additionalContact"
android:textAppearance="?android:attr/textAppearanceMedium"
android:drawableEnd="#drawable/ic_expand_more_black_24dp"
android:layout_marginTop="08dp"
android:layout_marginStart="05dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:layout_marginEnd="50dp"
android:layout_gravity="center"
android:visibility="gone"
android:layout_marginTop="20dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Name"
android:layout_gravity="center"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Phone"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/or"
android:layout_gravity="center"
android:layout_marginTop="20dp" />
<LinearLayout
android:layout_width="220dp"
android:layout_height="40dp"
android:background="#drawable/shape"
android:layout_gravity="center_horizontal">
<ImageButton
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#drawable/phone2"
android:layout_gravity="center"
android:layout_marginStart="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/addFromContacts"
android:layout_gravity="center"
android:layout_marginStart="20dp" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_marginLeft="48dp"
android:hint="#string/contact1"
android:layout_marginTop="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:focusable="true"
android:focusableInTouchMode="true">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:background="#drawable/ic_description_black_48dp"
android:layout_marginTop="10dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginEnd="10dp"
android:hint="Instruction"
android:layout_gravity="center"
android:layout_marginLeft="10dp" />
</LinearLayout>
</LinearLayout>
Activity from on which the layout is inflated.
View newDestination;
ViewGroup parent;
nextDestination.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
removeDestination.setVisibility(View.VISIBLE);
newDestination = getLayoutInflater().inflate(
R.layout.next_destination_layout, addDestination, true);
}
});
removeDestination.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
parent = (ViewGroup)destination.getParent();
parent.removeView(destination);
}
});
How to achieve this?? Please help...
{ ll.removeView(view)// to remove particular view
ll.removeViewAt(position);// to remove view from particular position
}
I have a listview with some texts in it like this
and I want to expand each item to like this
I have seen this answer(How can I make a cell in a ListView in Android expand and contract vertically when it's touched?), here it doesn't changes to a new view, but just changes the height.
UPDATE:list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:clickable="true"
android:background="#drawable/list_selected">
<RelativeLayout
android:id="#+id/relaboveline1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="#+id/sidebar"
android:layout_width="15dp"
android:layout_height="match_parent"
android:background="#4ED6CA" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:weightSum="100"
android:layout_toRightOf="#+id/sidebar"
android:layout_toEndOf="#+id/sidebar">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="20">
<RelativeLayout
android:id="#+id/cal"
android:layout_width="60dp"
android:layout_height="match_parent">
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="22"
android:textColor="#FF8801"
android:textStyle="bold"
android:layout_centerHorizontal="true"
android:textSize="35sp"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/month"
android:textColor="#FF8801"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/date"
android:textSize="20sp"
android:text="MAY" />
<TextView
android:id="#+id/year"
android:textColor="#FF8801"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/month"
android:textSize="20sp"
android:text="2015" />
</RelativeLayout>
<View
android:id="#+id/divider"
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_toRightOf="#+id/cal"
android:layout_toEndOf="#+id/cal"
android:background="#DADADA" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="60">
<RelativeLayout
android:id="#+id/content"
android:layout_width="200dp"
android:paddingTop="5dp"
android:paddingLeft="8dp"
android:layout_height="match_parent">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:text="High School Graduation" />
<TextView
android:id="#+id/contentdesc"
android:layout_width="wrap_content"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:text="#string/dummy" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="20">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:text="5B"
android:id="#+id/classDiv" />
<RelativeLayout
android:layout_below="#+id/classDiv"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerInParent="true"
android:src="#drawable/star_yellow" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<View
android:id="#+id/line2"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_below="#+id/relaboveline1"
android:background="#DADADA" />
You can use ExpandableListView:
You define a custom layout for the child (the details when you click on the row)
You define an public class ExpandableAdapter extends BaseExpandableListAdapter
Override the method
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
....
}
where you implement your detail layout (child layout).
Override the method
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
...
}
where you implement the layout like the ListView.
Set the custom adapter in your ExpandableListView instance
If you want to have more info give a look at my post here http://www.survivingwithandroid.com/2013/01/android-expandablelistview-baseexpandablelistadapter.html
Have you tried ExpandableListView with only one child view for each group view? then you can expand and collapse rows as you want.