I want to update the style of the selected item inside a ViewPager.
How can I do this?
This is the UI design. As you can see, the "November" tab is selected, so the corresponding bar is highlighted in yellow.
The way I've implemented this is a ViewPager with a custom item (white, not highlighted):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:layout_width="142dp"
android:layout_height="275dp"
android:layout_margin="0dp"
app:cardElevation="0dp"
app:cardBackgroundColor="#android:color/transparent">
<TextView
android:id="#+id/monthly_spend_month"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/December"
android:textColor="#color/aluminum"
android:textSize="20sp"
android:textStyle="normal"
android:layout_marginStart="22dp"
android:layout_marginTop="34dp"/>
<RelativeLayout
android:id="#+id/monthly_spend_card"
android:layout_marginTop="120dp"
android:layout_marginStart="22dp"
android:layout_width="120dp"
android:layout_height="155dp"
android:background="#drawable/monthlyspend_card_bg_inactive">
<TextView
android:id="#+id/monthly_spend_text"
android:textColor="#color/almost"
android:layout_marginTop="50dp"
android:layout_marginStart="22dp"
android:text="Total
spent"
android:textSize="#dimen/balanceDescTextSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/monthly_spend_amount"
android:textColor="#color/almost"
android:layout_marginTop="10dp"
android:layout_marginStart="22dp"
android:layout_below="#id/monthly_spend_text"
android:text="$ 254.98"
android:textSize="#dimen/balanceDescTextSize"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
I plan on doing the highlighting programmatically.
Here's some adapter code:
#NonNull
#Override
public Object instantiateItem(#NonNull ViewGroup container, int position) {
layoutInflater = LayoutInflater.from(context);
View view = layoutInflater.inflate(R.layout.monthlyspend_item, container, false);
TextView monthlySpendMonth, monthlySpendAmount;
monthlySpendCard = view.findViewById(R.id.monthly_spend_card);
monthlySpendMonth = view.findViewById(R.id.monthly_spend_month);
monthlySpendAmount = view.findViewById(R.id.monthly_spend_amount);
monthlySpendMonth.setText(monthlySpendings.get(position).getMonth());
monthlySpendAmount.setText(monthlySpendings.get(position).getAmountSpent());
container.addView(view, 0);
return view;
}
Any help would be appreciated!
I thing you are missing click listener :
view.setOnClickListener(new OnClickListener(){
public void onClick(View v){
// do you stuff here
}
});
((ViewPager)container).addView(view, 0)
Also inside instantiateItem() make int position as final.
you should change your model (in your case "monthlyspendings") at the selected item position.
then notify the adapter
adapter.notifyDataSetChanged()
and finally, custom selected view according to the model. for exapmle :
if(monthlySpendings.get(position).isSelected) monthlySpendCard.setBackgroundColor(Color.parseColor("#fcd14b"));
Related
when i click listview item which contains textview and checkbox, setOnItemClickListener not working
this is my java code
android listview contains checkbox setonItemclick not working
etiket_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
final Database dbD = new Database(context); // Db bağlantısı oluşturuyoruz. İlk seferde database oluşturulur.
Tags = dbD.Etiketler();
final int temp_id = Integer.valueOf(Tags.get(db.Etiketler().size()-position-1).get("tag_id"));
final int pozisyon=db.Etiketler().size()-position-1;
if (syac % 2 == 0) {
val_tag=val_tag+Tags.get(pozisyon).get("tag")+" ";
tag.setText(val_tag);
syac++;
} else {
String newTags = tag.getText().toString().replaceAll(Tags.get(pozisyon).get("tag"),"");
syac++;
tag.setText(newTags);
}
}
});
Here is my list item XML code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="false"
android:descendantFocusability="blocksDescendants"
android:weightSum="1">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.09"
android:background="#f8f8f8"
android:descendantFocusability="blocksDescendants"
android:id="#+id/item_li_frame">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="list_item_etiket2"
android:id="#+id/list_item_etiket2"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="16dp"
android:layout_marginRight="6dp"
android:textColor="#4a4a4a"
android:textStyle="bold"
android:focusableInTouchMode="false"
android:focusable="false"
android:textSize="16dp" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/etiket_checkBox"
android:layout_gravity="right|center_vertical"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_marginRight="16dp" />
</FrameLayout>
</LinearLayout>
Android listview contains checkbox setonItemclick not working
You have placed a TextView and CheckBox in a FrameLayout so the checkBox lies above the textView and consumes the touch events. Place them in a different layout such as LinearLayout
SOLVED THE CODE BELOW WORKS
If I have a layout similar to the one below:
Those five temp EditTexts represent some info the user can enter (like the price of an item, the order number, etc.) If the user wants to add another item they would click on the Add button and I want another 5 textviews to appear on the screen right above the two buttons but right below the previous set of the 5 EditTexts. Can someone give me a starting point on how I would do this.
My layout of the fragment goes like this:
I have a top level linear layout (Vertical Orientation).
Then a scrollview.
Inside the scrollview I have another linear layout.
In that linear layout I have those five EditText objects and the two buttons
The view above is a fragment (defined in the file below) which I pass to my FragmentAdapter in my MainActivity file:
public class Device extends Fragment {
ScrollView scrollView;
LinearLayout ll;
#Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.device_view, container, false);
scrollView = (ScrollView) rootView.findViewById(R.id.device_scroll_view);
ll = (LinearLayout) rootView.findViewById(R.id.layout_in_scrollview);
Button addButton = (Button) rootView.findViewById(R.id.add_another_device_button);
addButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
View temp = inflater.inflate(R.layout.edit_text_view_objects, container, false);
ll.addView(temp);
}
});
return rootView;
}
}
Here is my layout file for this fragment:
<LinearLayout 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/device_fragment_linear_layout"
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="DeviceFragment"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/device_scroll_view">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_horizontal">
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="40dp">
<Button
android:id="#+id/submit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Submit" />
<Button
android:id="#+id/add_another_device_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add"
android:layout_alignParentRight="true"/>
</RelativeLayout>
</LinearLayout>
edit_text_view_objects.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name of Master Device"
android:gravity="center"
android:textSize="15dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Device Name"
android:gravity="center"
android:textSize="15dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Max SMS per day"
android:gravity="center"
android:textSize="15dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="15dp"
android:hint="Carrier Name"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:gravity="center"
android:layout_gravity="center"
android:hint="OS Version"
android:layout_marginTop="10dp"/>
</LinearLayout>
in your XML take
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/device_scroll_view">
<LinearLayout
android:id="#+id/layoutDynamic"a
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_horizontal">
</LinearLayout>
</ScrollView>
and create one more XML for your Item and design accordingly (It will add dynamically when you click on ADD)
dynamic_item.xml
<LinearLayout 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/device_fragment_linear_layout"
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="DeviceFragment"
android:orientation="vertical">
<TextView
android:id="#+id/etDynamic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:gravity="center"
android:layout_gravity="center"
android:hint="Color"
android:layout_marginTop="10dp"/>
</LinearLayout>
so come to java Code
// take the reference of LinearLayout
linearLayout = (LinearLayout) romptView.findViewById(R.id.layoutDynamic);
// Take the reference of Add button
Button addButton = (Button) rootView.findViewById(R.id.add_another_device_button);
addButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final View addView = layoutInflater1.inflate(R.layout.dynamic_row, null);
final TextView textView1 = (TextView) addView.findViewById(R.id.etDynamic);
textView1.setText(otheret.getText().toString().trim()); otheret.setText(""); linearLayout.addView(addView);
}
});
#and if you want to remove particular item
removeIcon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
addView.getParent()).removeView(addView);
}
});
You can add these EditText through code at runtime
we can solve this, using List/Recycler view efficiently/easily
when ever you clicking on ADD add the item to list and notify the Recycler view adapter
and and removing also easy you just delete the item from list based on recycler View position.
No need to create Dynamic View here recycler view will do the job
// In Main Layout
<android.support.v7.widget.RecyclerView
android:id="#+id/recycleView_Stops"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/layoutSaveBottom"
android:layout_below="#+id/ll1"
android:layout_marginTop="#dimen/pad_10dp"
app:layout_behavior="#string/bottom_sheet_behavior" />
<TextView
android:id="#+id/tvAddOther"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="#string/icon_plus"
android:textColor="#color/colorPrimary"
android:textSize="40sp"
app:customFontPath="#string/roboto_regular" />
// design your layout item
---------------------
and when clicking on Add set user entered details
addOther.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
RouteElements routeElements = new RouteElements();
routeElements.setLatitude(latitude);
routeElements.setLongitude(longitude);
routeElements.setStopName(otheret.getText().toString().trim());
routeElementsArrayList.add(routeElements);
routeStopsAdapter.notifyDataSetChanged();
});
And in Your Adapter for removing the item
public void remove(int position) {
if (position < routeElementsArrayList.size()) {
routeElementsArrayList.remove(position);
notifyDataSetChanged();
}
}
I am trying to change the display on my android screen when you click on a textview. This textview is inside a tab which is inside a tabhost. I created a fragment which would overlay on top of this tab when you click on it but having issues doing.
In my main activity I got this code;
tabHost.getTabContentView().findViewById(R.id.currentMoney).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
switch(v.getId()){
case R.id.currentMoney:
android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.tab2, new OverviewFragment());
transaction.commit();
}
}
});
This is the code that I have in my overview java class
public class OverviewFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.home_tab_transactionhistory, container, false);
}
}
What happens is when I run this home_tab_transactionhistory xml file comes up right underneath what ever I had before. Doesn't even show fully what ever I have got in the home_tab_transactionhistory xml file.
Below I have listed the xml code of the page that should take you to another page when you click on a text view;
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#369742"
android:gravity="start|end"
android:longClickable="true">
<TabHost
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/tabHost"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:clickable="false">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:background="#5DAD68"
android:clickable="false"
android:measureWithLargestChild="true"
android:orientation="horizontal"
android:layout_weight="1.04"
android:longClickable="false"
android:paddingTop="10dp"
android:paddingLeft="30dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"></TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="false">
<LinearLayout
android:id="#+id/tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:clickable="false"
android:background="#FFFFFF"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/currentMoney"
android:fontFamily="sans-serif-light"
android:onClick="showCurrentAccountMoney"
android:id="#+id/currentMoney"
android:paddingTop="5dp"
android:layout_gravity="center_horizontal"
android:textColor="#ff000000"
android:textSize="40dp" />
id of the textview is currentMoney
Please can someone help me fix this issue.
You should post the xml layout file where there is your clickable text view. To make the new Fragment overlay, you should add it to a FrameLayout which places its childs on top of each other.
i'm developing an android project which it has a viewpager. i wrote an adapter for my viewpager and my adapter consist of s scrollview and some views inside that.
i want when user click on the scrollview, something happen (i wrote this part too and test it and it works).
i implement onClickListener for my scrollview but it's not triggered when user click on that.
i have already read this but it's not work for me.
my code for onClickListener is here
rootView = inflater.inflate(R.layout.level_selector_list_view_adapter, container, false);
ScrollView scroll = (ScrollView) rootView.findViewById(R.id.level_selector_view_scroll_view);
scroll.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View arg0)
{
Log.e(MainActivity.WATERMELON_TAG, "Click!!!");
}
});
and my layout code is this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="#dimen/level_selector_values_main_page_view_pager_width"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ScrollView
android:id="#+id/level_selector_view_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
tools:ignore="UselessParent" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
tools:ignore="UselessParent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:clickable="false"
android:orientation="vertical" >
<ImageView
android:id="#+id/level_selector_view_pager_adapter_level_logo"
android:layout_width="#dimen/level_selector_values_view_pager_adapter_level_logo_width"
android:layout_height="#dimen/level_selector_values_view_pager_adapter_level_logo_height"
android:layout_gravity="center_horizontal"
android:layout_marginTop="#dimen/level_selector_values_view_pager_adapter_level_logo_top_margin"
android:clickable="false"
android:scaleType="fitXY"
tools:ignore="ContentDescription" />
<TextView
android:id="#+id/level_selector_view_pager_adapter_level_name"
android:layout_width="#dimen/level_selector_values_view_pager_adapter_level_name_width"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="#dimen/level_selector_values_view_pager_adapter_level_name_top_margin"
android:clickable="false"
android:gravity="center"
android:textColor="#color/level_selector_values_level_name_font_color"
android:textSize="#dimen/level_selector_values_level_name_font_size" />
<TextView
android:id="#+id/level_selector_view_pager_adapter_level_score"
android:layout_width="#dimen/level_selector_values_view_pager_adapter_level_score_width"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="#dimen/level_selector_values_view_pager_adapter_level_score_top_margin"
android:clickable="false"
android:gravity="center"
android:textColor="#color/level_selector_values_level_name_font_color"
android:textSize="#dimen/level_selector_values_font_size" />
</LinearLayout>
<ImageView
android:id="#+id/level_selector_view_pager_adapter_lock"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:alpha="0.75"
android:clickable="false"
android:scaleType="fitXY"
android:src="#drawable/lock"
tools:ignore="ContentDescription" />
</FrameLayout>
</ScrollView>
The child Views of your ScrollView are consuming the click events you do on the ScrollView.
The solution to this problem is to set the onClickLIstener to the immediate child of the ScrollView, the FrameLayout in your case.
Don't forget to set the layout to "clickable".
Furthermore, I recommend not to use the FrameLayout at all, since it is just a useless container. Instead, just let the LinearLayout that is currently the child of the FrameLayout be the next child to the ScrollView.
try:
public class ClassName implements OnClickListener {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_child, container, false);
ScrollView scrollView= (ScrollView) root.findViewById(R.id.my_ScrollView);
scrollView.setOnClickListener(this);
return root;
}
#Override
public void onClick(View v) {
Log.e(MainActivity.WATERMELON_TAG, "Click!!!");
}
}
I am trying to make a simple Checkbook app, whose MainActivity stores a list of transactions. I would like a TextView at the top and bottom of the screen that show the account balance and an option to add a new transaction, respectively. I would like a list of transactions in between that scroll. I was able to implement a ListView and add a header and footer view, but if the transaction list exceeds the size of the screen the headers and footers can scroll off screen.
Is there any way to position a ListView within the linear layout, or freeze the headers/footers to stay on the screen?
Here is my XML file so far:
<TextView
android:id="#+id/header_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/default_header_string">
</TextView>
<ListView
android:id="#+id/transaction_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
<TextView
android:id="#+id/footer_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/add_transaction_string">
</TextView>
And here is my onCreate, which has no syntax errors but I am unable to click the footerview to add a transaction:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_checkbook);
ListView list = (ListView) findViewById(R.id.transaction_list_view);
// Create a new Adapter
mAdapter = new TransactionAdapter(list.getContext());
// Inflate footerView and headerView
LayoutInflater inflater = getLayoutInflater();
TextView headerView = (TextView) inflater.inflate(R.layout.header_view, null);
TextView footerView = (TextView) inflater.inflate(R.layout.footer_view, null);
// Set listener for footerView
footerView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
Intent transactionIntent = new Intent(CheckbookActivity.this, AddTransactionActivity.class);
startActivityForResult(transactionIntent, ADD_TRANSACTION_REQUEST);
}
});
list.setAdapter(mAdapter);
}
use the below code. This will satisfy your requirement. I tried this and working for me.
Relative layout with below,above attributes. Relativelayout is better than Linear layout with weight method.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/relative"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:gravity="center_horizontal"
android:text="ListView Heading" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:text="ListView Footer" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/textView1"
android:layout_above="#id/textView2"
></ListView>
The UI will like this
Try this way, hope this will help you to solve your problem.
Instead of using header/footer just put as below code in your XML:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/header_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/default_header_string">
</TextView>
<ListView
android:id="#+id/transaction_list_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</ListView>
<TextView
android:id="#+id/footer_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add_transaction_string">
</TextView>
</LinearLayout>
Yes, you can do it with weightsum and layout_weight in linearlayout and also you can create this type of view using RelativeLayout.
1) In LinearLayout just add weightsum="1" to your linearlayout and add layout_weight="0.2" to each of your header and footer and add layout_weight="0.6" to your listview.
2) In relativeLayout add alignParentTop to your header and alignParentBottom to your footer and set listview to layout_below="#+id/header" and layout_above="2+id/footer"
I found a possible solution for your problem from a similiar post. Hope this helps you.
For what you are trying to accomplish to freeze the header/footer. It will be easier to use a relative layout to position the header/footer then have your listview in the middle
<RelativeLayout ...>
<TextView
android:id="#+id/header_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="#string/default_header_string">
</TextView>
<ListView
android:id="#+id/transaction_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/header_view"
android:layout_above="#+id/footer_view">
</ListView>
<TextView
android:id="#+id/footer_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:text="#string/add_transaction_string">
</TextView>
</RelativeLayout>
You can use a LinearLayout for this task. But I don't recommend it as it's a bit "hacky".
Get all the elements in a array: Example:- (weatherArray)
Loop through all the elements :-
Example:-
mainLayout = ((LinearLayout)refreshObj.get("mainLayout"));
mainLayout.removeAllViews();
for (int i = 0; i < weatherArray.length(); i++) {
View childView = getLayoutInflater().inflate(R.layout.weather_row4_item, mainLayout,false);
TextView todayTempStatus = (TextView) childView.findViewById(R.id.todayTempStatus);
todayTempStatus.setText("");
}
This is an example without using listview, which we will populate lienarlayout using child view.