This is my fragment where I have called the recycler view:
public class sgpa_frag extends Fragment {
//View view;
RecyclerView recyclerview;
adapter_sgpa ac;
ArrayList<POJO> sgpaArrayList;
public sgpa_frag() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_sgpa_frag, container, false);
recyclerview= (RecyclerView) view.findViewById(R.id.rc1);
sgpaArrayList= new ArrayList<>();
ac= new adapter_sgpa(sgpaArrayList);
recyclerview.setLayoutManager(new LinearLayoutManager(getContext(),RecyclerView.VERTICAL,true));
recyclerview.setAdapter(ac);
Fetchdata1();
return view;
}
private void Fetchdata1()
{
dbmanager db= new dbmanager(getContext());
Cursor cursor= db.fetch_data1();
if (cursor!= null){
// cursor.moveToFirst();
while (cursor.moveToNext()){
POJO pj= new POJO();
pj.setSname(cursor.getString(0));
pj.setSemester(cursor.getString(1));
pj.setSgpa(cursor.getString(2));
pj.setPercent(cursor.getString(3));
pj.setSchemes(cursor.getString(4));
sgpaArrayList.add(pj);
}
ac= new adapter_sgpa(sgpaArrayList);
}
}
}
This is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<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=".drawernav.bottom_navi.recycler_view.sgpa_frag">
<!-- TODO: Update blank fragment layout -->
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rc1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="60dp">
</androidx.recyclerview.widget.RecyclerView>
</FrameLayout>
I want my Recycler view to start displaying from the top item and not from the middle item . Can anyone tell me what changes should I make in my code ? Thanks in advance .
I mean to say that, it is like this:
And I want it to be like this:
You should set layout width and height of the recyclerview to match_parent.
The actual reason for your issue is probably the reverseLayout of your your linear layout manager. This has the effect as scrolling down the recyclerview.
Use this instead:
new LinearLayoutManager(getContext(),RecyclerView.VERTICAL,false)
Try adding
android:descendantFocusability="blocksDescendants"
to the recyclerview parent layout
Edit:
I think it is not a problem with RecyclerView instead if you are using a cordinator layout as root layout, try giving margin to your FrameLayout of 60
<!-- TODO: Update blank fragment layout -->
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rc1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop ="60dp" //approx for toolbar height
android:paddingBottom="60dp">
</androidx.recyclerview.widget.RecyclerView>
Add this into you code
mRecyclerView.smoothScrollToPosition(0);
Related
Here is what I am trying to do:
What is the simplest way to create rows that scroll together and are composed of variable sized clickable Views with the same height on Android
Basically create variable width columns that have the same width in every row. Also need to add, delete and add listeners. Seems like a fairly simple task, but I am finding Android's GUI library a lot harder to figure out than Java's and WPF's GUI library.
Here is my RecyclerView:
public class MainActivity extends AppCompatActivity {
private RecyclerView ampRecyclerView;
private RecyclerView.Adapter ampAdapter;
private RecyclerView.LayoutManager ampLayoutManager;
List<FunctionView> myDataset = new ArrayList<FunctionView>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setUpRecyclerView();
}
private void setUpRecyclerView() {
LinearLayout linearLayout = findViewById(R.id.main_ll);
linearLayout.setWillNotDraw(false);
ampRecyclerView = (RecyclerView) findViewById(R.id.AmpRecyclerView);
// use a linear layout manager
ampLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
ampRecyclerView.setLayoutManager(ampLayoutManager);
myDataset.add(new FunctionView(this));
myDataset.add(new FunctionView(this));
myDataset.add(new FunctionView(this));
// specify an adapter
ampAdapter = new MainActivityAdapter(myDataset, 1);
ampRecyclerView.setAdapter(ampAdapter);
}
}
My adapter
class MainActivityAdapter extends RecyclerView.Adapter<MainActivityAdapter.FunctionViewHolder> {
private List<FunctionView> views = new ArrayList<FunctionView>();
private List<LinearLayout> llViews = new ArrayList<>();
private int rows;
// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
public static class FunctionViewHolder extends RecyclerView.ViewHolder {
// each data item is just a string in this case
public LinearLayout linearLayout;
public FunctionViewHolder(LinearLayout v) {
super(v);
linearLayout = v;
}
}
// Provide a suitable constructor (depends on the kind of dataset)
public MainActivityAdapter(List<FunctionView> myDataset, int rows) {
views = myDataset;
this.rows = rows;
}
// Create new views (invoked by the layout manager)
#Override
public MainActivityAdapter.FunctionViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
LinearLayout linearLayout = (LinearLayout) LayoutInflater.from(parent.getContext())
.inflate(R.layout.function_holder, parent, false);
llViews.add(linearLayout);
MainActivityAdapter.FunctionViewHolder vh = new MainActivityAdapter.FunctionViewHolder(linearLayout);
return vh;
}
// Replace the contents of a view (invoked by the layout manager)
#Override
public void onBindViewHolder(MainActivityAdapter.FunctionViewHolder holder, int position) {
// - get element from your dataset at this position
// - replace the contents of the view with that element
int width = 0;
for(FunctionView fv : views){
holder.linearLayout.addView(fv);
width += fv.getWidth();
}
holder.linearLayout.setMinimumWidth(width);
//TODO set the data
// holder.functionView = views.get(position);
}
// Return the size of your dataset (invoked by the layout manager)
#Override
public int getItemCount() {
return rows;
}
I know there are glaring design flaws. I am trying to get the scrolling working first, because every layout I try doesn't work how I'd like.
Here is the layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_ll"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/AmpRecyclerView"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
and the holder:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:isScrollContainer="true"
android:nestedScrollingEnabled="true"
>
</LinearLayout>
as you said there are glaring design flaws, but you need to change the android:layout_height to wrap_content and android:layout_width to match_Parent.
if your item's hight is match_parent then your inner layout's hight becomes the recyclerview's hight then there is no room for other items so there will be no scrolling.
also, put something like a textView in it to be able to see the items.
another note, the name is supposed to be item not holder. holder is related to ViewHolder which is a totally different thing. you can name it according to your activity for example if Your activity name is MainActivity so your activity layout is activity_main, then you can call the inner layouts item_main
I recommend watching a tutorial on youtube or read an article from medium or anywhere (you can simply just google android recyclerview example) to learn the basics.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="#+id/txt_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SAMPLE"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:textSize="30sp"
/>
</LinearLayout>
I am new to Android TV development. I don't know which type of fragment to use. I want two achieve layout similar to above screenshot as jiocinema. Somehow I have achieved it using a two xml fragments inside activity layout. Second fragments loads screenshot after hitting an API so it loads after some time. As can be seen in the above screenshot I want the layout in two parts..top one with details and some buttons and the bottom one is a list of screenshots of that movie.
In my case the problem is, bottom list part takes the focus on loading this particular screen after that on pressing up button or any button it never loses focus and never goes on the top part.
Note: below fragment loads asynchronously, as it hits an api for screenshot urls
May be I haven't used proper fragments for this particular layout. Can someone point me to the code or help me out in deciding what to use for this kind of layout. As it can be achieved but navigation is the main thing.
code
activity layout
<?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="wrap_content"
android:background="#color/photo_label_box">
<fragment
android:id="#+id/detail_layout"
android:layout_width="match_parent"
android:name="com.DetailsActivityGame$Detalfragment"
android:layout_height="200dp"></fragment>
<fragment
android:id="#+id/row_layout"
android:layout_width="match_parent"
android:layout_below="#+id/detail_layout"
android:name="com.DetailsActivityGame$SampleFragmentC"
android:layout_height="wrap_content"></fragment>
</RelativeLayout>
Thanks
Try to use the RowSupportFragment in V4 Support Fragment for desired output.
Divide layout into two parts layout with buttons, description and below scrolling layout(Represent by RowSupportFragment)
//----------------------detail_layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/leader_background">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/main_layout"
//your own layout design for buttons and description
</RelativeLayout>
<fragment
android:name="FragmentScreenshots"
android:id="#+id/screenshot_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
//----------------Detailfragment--------------------
public static class Detailfragment extends Fragment {
public Detailfragment(){ }
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.detail_layout, container, false);
//————————your own implementation—————————————————————————
return view;
}
public static class FragmentScreenshots extends RowsSupportFragment {
private ArrayObjectAdapter mRowsAdapter = null;
public FragmentScreenshots() {
mRowsAdapter = new ArrayObjectAdapter(new ShadowRowPresenterSelector());
setAdapter(mRowsAdapter);
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//———————Provide data accordinally———————————
List<ScreenshotItem> list;
// Add a Related items row
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(
new ScreenshotCardPresenter(getActivity()));
for (ScreenshotItem s:list)
{
listRowAdapter.add(s);
}
HeaderItem header = new HeaderItem("Screenshots");
mRowsAdapter.add(new ListRow(header, listRowAdapter));
setAdapter(mRowsAdapter);
setOnItemViewClickedListener(new OnItemViewClickedListener() {
#Override
public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) {
if (item instanceof ScreenshotItem) {
}
else{
}
}
});
setOnItemViewSelectedListener(new OnItemViewSelectedListener() {
#Override
public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item, RowPresenter.ViewHolder rowViewHolder, Row row) {
}
});
}
#Override
public void setExpand(boolean expand) {
super.setExpand(true);
}
#Override
public void setOnItemViewClickedListener(BaseOnItemViewClickedListener listener) {
super.setOnItemViewClickedListener(listener);
}
#Override
public void setOnItemViewSelectedListener(BaseOnItemViewSelectedListener listener) {
super.setOnItemViewSelectedListener(listener);
}
}}
You have to use BrowseFragment for your purpose. It is composed of a RowsFragment and a HeadersFragment.
A BrowseFragment renders the elements of its ObjectAdapter as a set of rows in a vertical list. The elements in this adapter must be subclasses of Row.
This tutorial can help you to get started.
I have a RecyclerView in a DialogFragment. Both the Dialog fragment and recyclerview show though when the recyclerview fills beyond the view capacity it does not scroll.
?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="match_parent"
android:tag="FoodMenuTag"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.android.cop1803.MainActivity">
<View
android:id="#+id/divider3"
android:layout_width="1184dp"
android:layout_height="1dp"
android:layout_marginTop="#dimen/MarginTop_PDF_dividers"
android:layout_marginBottom="#dimen/MarginTop_PDF_dividers"
android:background="?android:attr/listDivider"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/kCal"
tools:layout_editor_absoluteX="8dp" />
<com.example.android.cop1803.MyRecyclerView
android:id="#+id/recycler_menuview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
app:layout_constraintTop_toBottomOf="#id/divider3"
/>
Here's my Dialog Fragment:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.recyclerview_menu, container, false);
mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_menuview);
return view;
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Bundle args = getArguments();
if(args != null) {
cartList = args.getParcelableArrayList("key");
MenuDialogFragmentAdapter adapter = new
MenuDialogFragmentAdapter(this.getActivity(), cartList);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setAdapter(adapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
}
}
#Override
public void onResume() {
// Get existing layout params for the window
ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes();
// Assign window properties to fill the parent
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.MATCH_PARENT;
getDialog().getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
// Call super onResume after sizing
super.onResume();}
Any help with getting this to work is much appreciated.
thanks,
Jim
It turned out I was not accounting for the full height of my recycler view. So it was actually working but the height was extending it beyond the bottom boundary. Once I made a few adjustments to the height it worked. Here's the XML that on landed on.
<com.example.android.cop1803.MyRecyclerView
android:id="#+id/recycler_menuview"
android:layout_width="match_parent"
android:layout_height="350dp"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
android:scrollbars="vertical"
app:layout_constraintVertical_bias="0.01"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/divider3" />
I don't like the height being a fixed value so I'll likely change via code.
thanks,
Jim
try adding nested scrolling to the recyclerview, see if its works.
recyclerView.setNestedScrollingEnabled(true);
I have a fragment with his class:
public class FormatShortFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.bag_format_short, container, false);
return rootView;
}
}
And this is his layout:
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</LinearLayout>
</RelativeLayout>
This fragment is shown by a FragmentPageAdapter.
The layout will grow when an user add an item from server (the origin of the item doesn't matter), and this item will be an horizontal linearlayout, with textview and edittext (item_name, item_value). This value can be modifiable, so must be an edittext, also, this edittext will receive values periodically from server, so can be updated automatically.
After explain this, how can I add this linearLayouts and his subviews to the GUI dynamically? and when should I update the interface?
Thanks a lot, any help is good received, I'm really lost on this on this themes.
EDITED WITH MODIFICATIONS:
I have modified the code in this way:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.bag_format_short, container, false);
return rootView;
}
#Override
public void onResume() {
super.onResume();
LinearLayout parentLinear = (LinearLayout) getActivity().findViewById(R.id.short_container);
for (int i = 1; i<10; i++ ){
LinearLayout innerLinear = (LinearLayout) new LinearLayout(getActivity());
TextView itemName = new TextView(getActivity());
itemName.setText("Nombre");
EditText itemValue = new EditText(getActivity());
itemValue.setText("Valor");
innerLinear.addView(itemName);
innerLinear.addView(itemValue);
parentLinear.addView(innerLinear);
}
}
#Override
public void onStart() {
super.onStart();
}
#Override
public void onStop() {
super.onStop();
}
And the fragment layout has been modified on this way:
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<LinearLayout
android:id="#+id/short_container"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</LinearLayout>
</RelativeLayout>
Now the layout is growing in each for iteration.
In this point i have another problems, I hope you can help me with this.
- How can I generate a LayouParams object with attributes like gravity or weigth?
- How can I pass data from MainActivity to the Fragment?
- And how can i force the Fragment view to be raloaded with new data?
Also i need to know how bind a clickListener event to programatically linearLayouts added, i need modify some values on server depending on the name and the edited value.
Thanks a lot for this, you are saving my life.
you Can easily Update UI of Fragment on Button click or any event just
Like in Activity. You can get any view by
getActivity().findViewById()
See Example, It will help you to undersatand:-
public class FragmentTab3 extends SherlockFragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragmenttab3, container, false);
return rootView;
}
#Override
public void onResume() {
super.onResume();
}
#Override
public void onStart() {
super.onStart();
LinearLayout linear = (LinearLayout) getActivity().findViewById(R.id.linear);
Button button = new Button(getActivity());
button.setText("Click Me");
linear.addView(button);
}
#Override
public void onStop() {
super.onStop();
}
}
If you want to add subview to a layout dynamically, take a look at RecyclerView in android documentation. Sounds like what you're looking for.
My layout was working fine before I switched it to use fragments inside the DrawerLayout. After that the ListView in the main view ghosts a copy of the list when scrolling.
The ListView contents scroll, but a copy of the first page remains on screen. I've been logging debug messages and there is no second copy of listview created, and no second copy of data sent from the adapter.
The layout for the activity uses DrawerLayout with fragments before switching to fragments it worked fine.
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="400dp"
android:layout_height="800dp">
<!-- The main content view -->
<fragment android:name="com.nosweatbudgets.receipts.ReceiptsFragment"
android:id="#+id/receipts_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<!-- The navigation drawer -->
<fragment android:name="com.nosweatbudgets.navigate.NavigateFragment"
android:id="#+id/navigate_fragment"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
/>
</android.support.v4.widget.DrawerLayout>
The fragment classes are each very simple.
ReceiptsFragment's onCreateView looks like this.
View view = inflater.inflate(R.layout.receipts, container, false);
_adapter = new ReceiptsAdapter(inflater);
ListView list = (ListView) view.findViewById(R.id.receipt_list);
list.setAdapter(_adapter);
_adapter.Refresh();
return view;
NavigateFragment's onCreateView is basically the same with a different adapter. It's the ReceiptsFragment that is ghosting while the NavigateFragment does not ghost. Yet they can basically the same approach.
View view = inflater.inflate(R.layout.navigate, container, false);
_navigate = new NavigateAdapter(inflater);
// setup the list view for the side
ListView list = (ListView) view.findViewById(R.id.left_drawer);
list.setAdapter(_navigate);
_navigate.Refresh();
return view;
For the above fragment classes I'm using the following layouts.
receipts.xml looks like this.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/receipt_list"/>
</RelativeLayout>
navigate.xml looks like this.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ListView
android:id="#+id/left_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:background="#EEEEEE"/>
</RelativeLayout>
The pull out navigate listview works just fine, but the main receipts listview has the ghosting problem.
I'm completely stumped as to what is causing this.
EDIT:
Here is how views are created in the ReceiptsAdapter.
public View getView(int position, View convertView, ViewGroup parent)
{
View view = convertView;
if (view == null)
{
view = _inflater.inflate(R.layout.receipt, null);
}
TextView txt_vendor = (TextView) view.findViewById(R.id.receipt_vendor);
TextView txt_category = (TextView) view.findViewById(R.id.receipt_category);
TextView category_btn = (TextView) view.findViewById(R.id.category_btn);
Model receipt = _receipts.get(position);
int vendor_id = receipt.getAsInteger("smart_vendor_id");
int category_id = receipt.getAsInteger("smart_category_id");
if (_vendors.indexOfKey(vendor_id) >= 0)
{
txt_vendor.setText(_vendors.get(vendor_id));
}
else
{
txt_vendor.setText("Select Vendor");
}
if (_categories.indexOfKey(category_id) >= 0)
{
String cat = _categories.get(category_id);
txt_category.setText(cat);
category_btn.setText(Category.ShortTitle(cat));
category_btn.setBackgroundColor(Category.Color(cat));
//txt_category.setBackgroundColor(c);
}
else
{
txt_category.setText("Select Category");
category_btn.setText("N/A");
}
((TextView) view.findViewById(R.id.receipt_amount)).setText("$" + receipt.getAsString("amount"));
((TextView) view.findViewById(R.id.receipt_payment)).setText(receipt.getAsString("payment"));
((TextView) view.findViewById(R.id.receipt_date)).setText(receipt.getAsString("receipt_date"));
return view;
}
EDIT:
This is how the Activity for the layout attaches the fragments via the onCreate method.
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// the layout uses fixed width/size, because the layout editor won't render match_parent.
// so I replace the layout parameters here with match_parent.
DrawerLayout layout = (DrawerLayout) getLayoutInflater().inflate(R.layout.main, null);
DrawerLayout.LayoutParams param = new DrawerLayout.LayoutParams(ViewGroup.LayoutParams
.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
layout.setLayoutParams(param);
setContentView(layout);
// configure this activity
StyleActionBar();
// Add the fragments
getSupportFragmentManager().beginTransaction()
.add(R.id.navigate_fragment, new NavigateFragment())
.add(R.id.receipts_fragment, new ReceiptsFragment())
.commit();
}
I mistakenly followed the fragments tutorial incorrectly, and created both a static fragment in the layout XML and also created a dynamic fragment for the same class at run-time.
The main layout used the <fragment> tag to create a fragment which is automatically attached at runtime via the android:name property.
This is what I have in my layout.xml
<fragment android:name="com.nosweatbudgets.receipts.ReceiptsFragment"
android:id="#+id/receipts_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
That was enough to create the fragment, but I mistakenly added code from the fragments tutorial in my activity as follows.
getSupportFragmentManager().beginTransaction()
.add(R.id.navigate_fragment, new NavigateFragment())
.add(R.id.receipts_fragment, new ReceiptsFragment())
.commit();
That added two additional fragment views to the activity at runtime. This resulted in two listviews for the same position.
What appeared to be a ghosting artifact was infact two fragments for the same class on top of each other. Removing the dynamic creation in onCreate resolved my problem.