Kotlin - Android can we implement OnClickListener on Class? - kotlin-android-extensions

I'm starting out with Kotlin and seems that onClick does not trigger if I implement it on an Activity Class
class MainActivity : AppCompatActivity(), View.OnClickListener{
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
tvTitle.text = "Hi There"
// tvTitle.setOnClickListener { this } // NOT WORKING??
tvTitle.setOnClickListener { doSomething() }
}
override fun onClick(v: View) {
Log.d("click", "Hello")
}
fun doSomething(){
Log.d("do", "Something")
}
}
I'm using Android Studio 3.0 with kotlin_version of 1.1.51, thank you in advance

Try this
class MainActivity : AppCompatActivity(), View.OnClickListener{
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
tvTitle.text = "Hi There"
tvTitle.setOnClickListener(this)
// tvTitle.setOnClickListener { doSomething() }
}
override fun onClick(v: View) {
Log.d("click", "Hello")
}
fun doSomething(){
Log.d("do", "Something")
}
}

This is my kotlin code :
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.LinearLayout
import android.widget.Toast
class Activity_T : AppCompatActivity(), View.OnClickListener {
private var linear_exit: LinearLayout? = null
private var linear_history: LinearLayout? = null
private var linear_recipe: LinearLayout? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
initView()
setOnClicks()
}
private fun setOnClicks() {
linear_exit!!.setOnClickListener(this)
linear_history!!.setOnClickListener(this)
linear_recipe!!.setOnClickListener(this)
}
private fun initView() {
linear_exit = findViewById(R.id.linear_exit)
linear_history = findViewById(R.id.linear_history)
linear_recipe = findViewById(R.id.linear_recipe)
}
override fun onClick(v: View) {
val item_id = v.id
when (item_id) {
R.id.linear_recipe -> Toast.makeText(this, "recipe", Toast.LENGTH_SHORT).show()
R.id.linear_history -> Toast.makeText(this, "history", Toast.LENGTH_SHORT).show()
R.id.linear_exit -> Toast.makeText(this, "exit", Toast.LENGTH_SHORT).show()
}
}
}
And this is part of my xml layout that had onclicks:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/linear_exit"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#color/border_green"
android:gravity="center">
<net.kibotu.heartrateometer.utils.MyTextView
android:textSize="13sp"
android:textColor="#android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/exit" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear_history"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#color/border_green"
android:gravity="center">
<net.kibotu.heartrateometer.utils.MyTextView
android:textSize="13sp"
android:textColor="#android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/history" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear_recipe"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#color/border_green"
android:gravity="center">
<net.kibotu.heartrateometer.utils.MyTextView
android:textSize="13sp"
android:textColor="#android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/recipe" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

try println("Something") first.

You can try this way.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val tvTitle = findViewById<TextView>(R.id.tvTitle)
tvTitle.setText("Hello Kotlin")
tvTitle.setOnClickListener(object : View.OnClickListener{
override fun onClick(v: View?) {
Toast.makeText(this#MainActivity,"You Clicked on " + tvTitle.text.toString(),Toast.LENGTH_SHORT).show()
}
})
}

Related

Xamarin + MvvmCross 6.0 unable to implement tabs navigation

I'm building a simple Xamarin app using MvvmCross and I'm currently unable to implement tabs navigation.
I'm getting an Mvx Exception: viewpager or tablayout not found
This is my main activity:
[MvxActivityPresentation]
[Activity(Theme = "#style/MainTheme",ConfigurationChanges=Android.Content.PM.ConfigChanges.Orientation |
Android.Content.PM.ConfigChanges.ScreenSize)]
public class TabsRootView : MvxAppCompatActivity<TabsRootViewModel>
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.tabs_root_view);
if (bundle == null)
{
ViewModel.ShowInitialViewModelsCommand.Execute();
}
}
}
This is my tabs root view layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
local:popupTheme="#style/ThemeOverlay.AppCompat.Light"
local:layout_scrollFlags="scroll|enterAlways">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
local:tabGravity="center"
local:tabMode="scrollable" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
local:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
This is supposed to be one of my tabs content fragment (the other one looks the almost the same):
[MvxTabLayoutPresentation(TabLayoutResourceId = Resource.Id.tabs, ViewPagerResourceId = Resource.Id.viewpager, Title = "Bacheca", ActivityHostViewModelType = typeof(TabsRootViewModel))]
[Register(nameof(PostsView))]
public class PostsView : MvxFragment<PostsViewModel>
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
var view = this.BindingInflate(Resource.Layout.posts_view, null);
// RecyclerView
var recyclerView = view.FindViewById<MvxRecyclerView>(Resource.Id.recycler_view);
recyclerView.SetLayoutManager(new LinearLayoutManager(Activity));
recyclerView.HasFixedSize = false;
// Swipe touch helper
var callback = new SwipeItemTouchHelperCallback(ViewModel);
var touchHelper = new ItemTouchHelper(callback);
touchHelper.AttachToRecyclerView(recyclerView);
return view;
}
}

MVVMCross Data Binding not working

I have custom object in my ViewModel.
public MyObject PropertyName
{
get { return _propertyName; }
set
{
_propertyName = value;
RaisePropertyChanged(() => PropertyName);
}
}
I want to bind only one of its member to textview in my droid view. Found this link:
Bind data of custom object to TextView in MvvmCross
And I am doing exactly like this. local:MvxBind = "Text Myobject.ItsMember"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="LabelCaption" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textColor="#android:color/white"
local:MvxBind="Text Myobject.ItsMember" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Checked the casing etc. but binding isn't working and I cannot see the string value appearing on the screen while I can print it in the debug window.
Any clues where I may be going wrong?
I cannot reproduce your issue on my end.
I've tried with:
public class MyViewModel : MvxViewModel
{
private MyModel _model; // this is a class member variable or class member field
public MyModel Model // this is a class member property
{
get => _model;
set => SetProperty(ref _model, value);
}
public MyViewModel()
{
Model = new MyModel { Name = "Herp" };
}
}
public class MyModel : MvxNotifyPropertyChanged
{
private string _name;
public string Name
{
get => _name;
set => SetProperty(ref _name, value);
}
}
Then given that MyViewModel is DataContext I bind using:
local:MvxBind="Text Model.Name"
Works just fine.
You can't bind to a type. You need to bind to an instance of the type. In order for the binding to work the way you have it set in the AXML you need something like
public class MyType
{
private string _ItsMember;
public string ItsMember
{
get
{
return _ItsMember;
}
set
{
_ItsMember = value;
RaisePropertyChanged (()=>ItsMember);
}
}
}
private MyType _MyObject;
public MyType MyObject
{
get
{
return _MyObject;
}
set
{
_MyObject = value;
RaisePropertyChanged(()=>MyObject);
}
}
This arrangement will allow MyObject.ItsMember to resolve to a string property value. If your property is not a string value, you will have to implement a converter which is a whole 'nother subject.

RecyclerView item dynamic Height micro stutter

I use an EndlessAdapter with a RecyclerView to fetch and load few hundred items from server.
Glide takes care to load the images for each row.
If user scrolls slowly, everything works fine, but when he flings, there are some micro stuttering in scrolling.
I think that this happens due to different image height for each row, but I don't know how to eliminate it.
My adapter code:
public final class ImagesAdapter extends EndlessAdapter<Image, ImagesAdapter.imageHolder> {
#NonNull
private static Fragment mFragment;
private OnItemClickListener onItemClickListener;
private static int mScreenWidth;
private int layoutStyle;
public ImagesAdapter(#NonNull Fragment fragment, List<Image> images, int layoutStyle) {
super(fragment.getActivity(), images == null ? new ArrayList<Image>() : images);
mFragment = fragment;
setHasStableIds(true);
mScreenWidth = fragment.getResources().getDisplayMetrics().widthPixels;
this.layoutStyle = layoutStyle;
}
public void changeLayout(int layoutStyle){
this.layoutStyle = layoutStyle;
}
public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
this.onItemClickListener = onItemClickListener;
}
#Override
public long getItemId(int position) {
return (!isLoadMore(position)) ? mItems.get(position).getId() : -1;
}
#Override
protected imageHolder onCreateItemHolder(ViewGroup parent, int viewType) {
final imageHolder holder;
switch (layoutStyle) {
case 0:
default:
holder = new imageHolder(mInflater.inflate(R.layout.item_image_enhanced_optim, parent, false));
break;
case 1:
holder = new imageHolder(mInflater.inflate(R.layout.item_image, parent, false));
break;
}
return holder;
}
#Override
protected ProgressViewHolder onCreateItemProgressBarHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.progressbar_item, parent, false);
return new ProgressViewHolder(v);
}
#Override
public void onViewRecycled(RecyclerView.ViewHolder holder) {
super.onViewRecycled(holder);
if (holder instanceof ProgressViewHolder) {
((ProgressViewHolder) holder).progressBar.stop();
Timber.d("Stopped progressbar");
}
}
#Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder.getItemViewType() == VIEW_TYPE_ITEM) {
((imageHolder) holder).bind(mItems.get(position));
} else {
((ProgressViewHolder) holder).start();
}
}
public void shuffle(List<Image> images) {
mItems.clear();
this.mItems.addAll(images);
notifyDataSetChanged();
}
final class imageHolder extends RecyclerView.ViewHolder {
#Bind(R.id.item_image_content)
FrameLayout container;
#Bind(R.id.item_image_img)
ImageView mImageView;
#Bind(R.id.item_image_name)
TextView imageName;
#Bind(R.id.item_author_name)
TextView imageAuthorName;
#Bind(R.id.item_author_image)
CircleImageView userImage;
#Bind(R.id.item_image_date)
TextView imageDate;
#Bind(R.id.item_image_comments)
TextView comments;
#Bind(R.id.item_view_on_map)
LinearLayout viewOnMap;
#Bind(R.id.item_view_share)
LinearLayout share;
#Bind(R.id.moreView)
LinearLayout moreView;
#Bind(R.id.progress_image)
LoadingView loadingView;
public imageHolder(View view) {
super(view);
ButterKnife.bind(this, view);
}
public void bind(#NonNull final Image image) {
container.setOnClickListener(new onImageClickListener(getAdapterPosition()));
userImage.setOnClickListener(new onAuthorClickListener(userImage, getAdapterPosition()));
viewOnMap.setOnClickListener(new onViewOnMapClickListener(getAdapterPosition()));
share.setOnClickListener(new onShareClickListener(getAdapterPosition()));
moreView.setOnClickListener(new onMoreClickListener(getAdapterPosition()));
loadingView.setVisibility(View.VISIBLE);
imageName.setText(image.getCombinedTitle());
imageAuthorName.setText(image.getAuthor());
imageDate.setText(image.getReadableDate());
comments.setText(image.getComments());
if(!loadingView.isCircling())
loadingView.start();
Glide.with(mFragment)
.load(image.getImageSrc(mScreenWidth))
.crossFade()
.override(mScreenWidth, (int) ((float) mScreenWidth / image.getRatio()))
.listener(new RequestListener<String, GlideDrawable>() {
#Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
#Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
loadingView.stop();
loadingView.setVisibility(View.GONE);
return false;
}
})
.into(mImageView);
}
}
and the row item
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
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/main_container"
android:layout_marginBottom="5dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="5dp"
app:cardCornerRadius="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/white">
<FrameLayout
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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/light_gray"
android:orientation="vertical">
<ImageView
android:id="#+id/item_image_img"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
tools:src="#drawable/header"
android:contentDescription="#string/img_content"
android:scaleType="fitXY" />
<FrameLayout
android:id="#+id/item_image_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:foreground="?selectableItemBackgroundBorderless"
android:orientation="vertical" />
</FrameLayout>
<include layout="#layout/item_image_header"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:layout_marginLeft="47dp"
android:visibility="visible"
android:paddingRight="10dp"
android:layout_marginBottom="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:gravity="center_vertical">
<ImageView
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_marginRight="3dp"
android:contentDescription="#string/descr" />
<TextView
android:id="#+id/item_image_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textColor="#color/colorPrimary"
android:textSize="15.0sp"
android:layout_gravity="center_vertical" />
</LinearLayout>
<TextView
android:id="#+id/item_image_comments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ellipsize="end"
android:maxLines="4"
tools:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:textColor="#android:color/primary_text_light_nodisable"
android:textSize="13.0sp"
android:layout_marginBottom="10dp" />
</LinearLayout>
<View
android:id="#+id/divider"
android:layout_width="match_parent"
android:background="#drawable/divider_shape"
android:layout_height="0.5dp" />
<include layout="#layout/item_image_bottom_buttons"/>
</LinearLayout>
Glide stop loading Images When you scroll list very fast it is done to improve the speed of Scrolling and avoiding any jitter
If you want to show images to your user I suggest you to use Picasso.
https://github.com/square/picasso
However Picasso is not good in caching the Images or has a limited Caching
or Either way u use placeHolder to represent the Image.
Edit
Heads up u can do it easily with Glide
Glide.with(getActivity())
.load("http://www.mediafile.com/12364f")
.placeholder(R.drawable.circle_placeholder_drawable)//this will show this image till your image is not fully loaded
.error(R.drawable.error_drawable)// if there is a problem in loading image an error image would be loaded instead
.into(holder.mFileTransferCircleImageView);

Android: implementing Checkbox List with ListFragment and ArrayAdapter

I am converting a working application to Fragments. My checkbox list is not displaying the labels, and I am guessing, the id's. I am new to Android/Java and this is my first post to Stackoverflow, so apologies if the question is simple or not following correct protocol.
My ListFragment is as follows:
import java.util.ArrayList;
import java.util.List;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
public class DistributionTransFragment extends ListFragment {
protected TextView subheader;
protected Context mContext;
protected DatabaseHandler db;
protected String user_id;
protected String user;
protected String recipients;
protected int number;
protected LayoutInflater inflater;
protected View v;
DistributionArrayAdapter dataAdapter = null;
public DistributionTransFragment(){
super();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
v = inflater.inflate(R.layout.distribution_fragment, container, false);
mContext = getActivity().getApplicationContext();
db = new DatabaseHandler(mContext);
subheader = (TextView)v.findViewById(R.id.textView2);
subheader.setText("Spent On?");
displayListView();
checkButtonClick();
return v;
}
private void displayListView() {
ArrayList<Participant> distributionList = new ArrayList<Participant>();
Participant participant;
List<User> users = db.getAllUsers();
for (User u : users) {
user_id = String.valueOf(u.getID());
user = u.getUser();
participant = new Participant(user_id, user, false);
distributionList.add(participant);
}
//create an ArrayAdaptar from the String Array
dataAdapter = new DistributionArrayAdapter(mContext, R.layout.distributionlist, distributionList);
setListAdapter(dataAdapter);
}
private class DistributionArrayAdapter extends ArrayAdapter<Participant> {
private ArrayList<Participant> distributionList;
public DistributionArrayAdapter(Context context, int textViewResourceId, ArrayList<Participant> distributionList) {
super(context, textViewResourceId, distributionList);
this.distributionList = new ArrayList<Participant>();
this.distributionList.addAll(distributionList);
}
private class ViewHolder {
TextView code;
CheckBox name;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
Log.v("ConvertView", String.valueOf(position));
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.distributionlist, null);
holder = new ViewHolder();
holder.code = (TextView) convertView.findViewById(R.id.code);
holder.name = (CheckBox) convertView.findViewById(R.id.checkBox1);
convertView.setTag(holder);
Log.d("HOLDER CODE", (holder.code).toString());
holder.name.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v ;
Participant participant = (Participant) cb.getTag();
participant.setSelected(cb.isChecked());
}
});
} else {
holder = (ViewHolder) convertView.getTag();
}
Participant participant = distributionList.get(position);
holder.name.setText(participant.getName());
holder.name.setChecked(participant.isSelected());
holder.name.setTag(participant);
return convertView;
}
}
private void checkButtonClick() {
Button myButton = (Button) v.findViewById(R.id.button1);
myButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
final ArrayList<Participant> distributionList = dataAdapter.distributionList;
// Do Stuff
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setMessage(tempTransaction);
builder.setCancelable(false);
builder.setPositiveButton("Commit", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Do More Stuff
Intent intent = new Intent(mContext, Home.class);
startActivity(intent);
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Do Other Stuff
Intent intent = new Intent(mContext, Home.class);
startActivity(intent);
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
}
}
My XML for the list is as follows:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/white"
android:padding="15dip" >
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:focusable="false"
android:focusableInTouchMode="false" />
<TextView
android:id="#+id/code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/checkBox1"
android:layout_alignBottom="#+id/checkBox1"
android:layout_toRightOf="#+id/checkBox1"
android:textSize="15sp" />
</RelativeLayout>
My XML for the fragment is as follows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/grey">
<RelativeLayout
android:id="#+id/subheader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/secondheader"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
style="#style/subheader" />
<TextView
android:id="#+id/textView3"
style="#style/info" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/subheader"
android:layout_above="#+id/footer"
android:orientation="vertical" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#id/footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/grey"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/button1"
style="#style/button.form"
android:text="#string/moneyspent" />
</LinearLayout>
</RelativeLayout>
Any help would be greatly appreciated.
I nutted it out, so thought I would post my answer in case others have the same problem. It was my context. It should have been:
mContext = getActivity();

The child views of the my parent ViewGroup remains unchanged and gets displayed in my new inflated layout at the bottom

Inflation using Array Adapter - The inflated layout does not fill my full screen.
The views present in the parent View Group get displayed at the bottom of my newly inflated layout. The inflation is not fitting full screen and causing display issues as in the image. Code is working fine but i am having problem with my Display. Please suggest possible solution. The parent XML is also an inflated layout list(Array Adapter).
Note
The layout is properly inflated by setting attachRoot=false
(Inflater.inflate(R.layout.chapterlayout, parent, false)).
Cannot process ViewGroup from ArrayAdapter , so unable to remove the parent views.
INFLATED XML 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:background="#drawable/my_background"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100" >
<TextView
android:id="#+id/ENo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="90"
android:text="1."
android:textColor="#0000FF"
android:textSize="15sp"
android:textStyle="bold" >
</TextView>
<TextView
android:id="#+id/EA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:paddingBottom="5sp"
android:text="My Text"
android:textColor="#0000FF"
android:textSize="15sp"
android:textStyle="bold" >
</TextView>
</LinearLayout>
<TextView
android:id="#+id/EE"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="My Text"
android:textColor="#0000FF"
android:textSize="15sp"
android:textStyle="bold" >
</TextView>
</LinearLayout>
PARENT XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/my_background">
<TextView
android:id="#+id/txt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#+id/label"
android:textSize="15sp"
android:textColor="#0000FF"
android:textStyle="bold"
android:background="#drawable/my_background">
</TextView>
</LinearLayout>
JAVA CODE
public class MyChapterAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
public MyChapterAdapter(Context context, String[] values) {
super (context, R.layout.main, values);
this.context = context;
this.values = values;
}
static class ViewHolder {
TextView ENo;
TextView EA;
TextView EE;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
LayoutInflater li = (LayoutInflater)
getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = li.inflate(R.layout.chapterlayout, parent, false);
holder = new ViewHolder();
holder.ENo = (TextView) convertView.findViewById(R.id.ENo);
holder.EA = (TextView) convertView.findViewById(R.id.EA);
holder.EE = (TextView) convertView.findViewById(R.id.EE);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
reDesignLayout(position, holder);
return convertView;
}
private void reDesignLayout(int position, ViewHolder h) {
// TODO Auto-generated method stub
String chapSplit[] =values[position].split("##");
h.ENo.setText(chapSplit[0]+". ");
h.EA.setText(chapSplit[1]);
h.EE.setText(chapSplit[2]);
}
}

Resources