I am very new in android development
Here is my problem
I created a custom list view consisting of text view and edit text
how can i validate that all edit text in custom list view are filled and then only accept button gets enable?
i have added text watcher for Edittext in getView() method
and in
public void afterTextChanged(Editable s)
{
View v;
EditText et;
ListView listView = (ListView) findViewById(R.id.listView1);
Button acceptButton= (Button) findViewById(R.id.Loginbutton);
for(int i=0;i<listView.getChildCount();i++)
{
v = listView.getChildAt(i);
et = (EditText) v.findViewById(R.id.txtedt);
// and then i got the entered edittext values and make enable/disable the acceptButtton on the bases of Edittext values.
}
Related
I am creating a list view. I am populating the listview using custom adapter. In my listview there is a text view widget. When I reset the value of that text view it displays fine. Then, I scroll down to get new values into the listView. But when I scroll up the text view widget resets back to the old populated value.
How can I retain the new value set by me persistently?
Here is the code of my listview adapter class where I populate the values to my listview. I am clicking on imageview in the listview that fires the event to set new text value to the text view widget in the list view.
private class MyListAdapter extends ArrayAdapter<CommentInfo> {
public MyListAdapter()
{
super(Comment.this, R.layout.listview_xml, myComments);
}
#Override
public View getView(final int position, final View convertView, final ViewGroup parent)
{
itemView = convertView;
if(itemView == null)
{
itemView = getLayoutInflater().inflate(R.layout.listview_xml, parent, false);
}
CommentInfo currentComment = myComments.get(position);
TextView tvLikes = (TextView) itemView.findViewById(R.id.tvLikes);
tvLikes.setText(currentComment.likes);
ImageView ivLikes = (ImageView) itemView.findViewById(R.id.likeBtn);
ivLikes.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
likePosition = position;
TextView tvlikes1 = (TextView) convertView.findViewById(R.id.tvLikes);
// Here, i will get the correct value from DB and set it.
// I am setting 999 for sample purpose
tvlikes1.setText("999");
}
});
return itemView;
}
}
I reset the value of listview's text view by getting convertView value in getView() argument in my above adapter class and accessing my listview's textview widget through it. Then, i set it to value 999 (for example purpose). Now, I scroll down to get more new listView items. But, on scrolling up the new value (999) that i set to the old item disappears.
Please help me with it.
I have done a test myself. The ListView adapter will always take the values from the myComments list, so in order to update the TextView as you want, you have to do like this:
ivLikes.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
likePosition = position;
myComments.get(position).setLikes("999");//Assume that your CommentInfo's likes is a string.
notifyDataSetChanged();
}
});
I have a TabPanel with two TabItems in ExtGwt. I want to make both the TabItem selectable/clickable but want to disable/read-only the content panel in the TabItem so that user can not perform any action like input text in the textbox or select any field etc. I tried various approaches but it didnot worked for me. I don't want to make the whole tab disable.
This answer may be useful: https://stackoverflow.com/a/2063082/1313968
An alternative approach is to disable all components in the panel, for example just pass your ContentPanel to the following method:
private void containerSetEnabled(final Container container, final boolean enabled) {
for (int widgetIndex = 0; widgetIndex < container.getWidgetCount(); ++widgetIndex) {
final Widget widget = container.getWidget(widgetIndex);
if (widget instanceof Container) {
containerSetEnabled((Container)widget, enabled);
}
else if (widget instanceof Component) {
((Component)widget).setEnabled(false);
}
}
}
The Context
I have a HomeActivity that contains a NewsFragment. The NewsFragment contains a ListView to display news items in a list. I have a ViewPager that is added as a header-view to the ListView. This ViewPager appears as a header to the list and contains a DateFragment to display the date. The first time the user opens the HomeActivity, I want "TODAY" to be the date. When the user swipes the DateFragment to the left, I want the date text to show "TOMORROW". Swipe again and it should show the day after tomorrow. Similarly, when the user swipes in the other direction, I want to display "YESTERDAY", the day before yesterday etc. The ViewPager should support swiping infinitely (or a very large number) in both directions.
Here's how they are nested - http://tinypic.com/r/31623qw/8. (I don't have the reputation to post images yet, but this diagram is super useful for understanding this question).
The Problem
For simplicity, I'm displaying the index of the fragment as the date. When I first open the app, I see "Date: 0" being displayed as the date in the DateFragment. When I swipe the fragment to the left (to go to the next day), I can see the next fragment appear with "Date: 1" being displayed, but almost immediately, the fragment disappears. Once the fragment disappears, nothing reappears, and I just see an empty container. I can swipe to bring back the "Date: 0" Fragment, but I can't see any other Fragments. (I'm using the - Infinite View Pager by Antony T. - https://github.com/antonyt/InfiniteViewPager)
The Gory Details
I have a HomeActivity that contains a NewsFragment. The NewsFragment contains a ListView to display news items as a list. Here is the layout.xml for the NewsFragment:
<?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="wrap_content">
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
I have a ViewPager that is dynamically added as a header to this list. So inside NewsFragment, I first initialize the ListView:
#Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.home_news_fragment, container, false);
list = (ListView) view.findViewById(android.R.id.list);
emptyView = view.findViewById(android.R.id.empty);
list.setEmptyView(emptyView);
return view;
}
Next, in onActivityCreated(), I initialize and load the header for the ListView, and then load the news feed items:
#Override
public void onActivityCreated(final Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
loadHeader();
loadNewsFeed();
}
In the loadHeader() method, I then dynamically create a LinearLayout container to contain my ViewPager. I create a PagerAdapter for the ViewPager and I wrap it with an InfiniteViewPager to allow infinite swiping in both directions. I then create a ViewPager and I add it to the LinearLayout container. I then add the container as a Header View to the ListView:
private void loadHeader()
{
final LinearLayout headerContainer = new LinearLayout(getActivity());
headerContainer.setId(R.id.header_container_id);
headerContainer.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
headerContainer.setOrientation(LinearLayout.VERTICAL);
// initialize the pager adapter for the view pager
PagerAdapter pagerAdapter = new HeaderPagerAdapter(getActivity().getSupportFragmentManager());
// Create a view pager. I use a custom implementation of a view pager I found from another Stackoverflow answer - WrapContentHeightViewPager - that allows ViewPager's layout.height to wrap content. The original ViewPager does not allow wrapping of content.
WrapContentHeightViewPager mViewPager = new WrapContentHeightViewPager(getActivity());
mViewPager.setId(R.id.view_pager_header);
mViewPager.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT));
// wrap pager to provide infinite paging with wrap-around
PagerAdapter wrappedAdapter = new InfinitePagerAdapter(pagerAdapter);
mViewPager.setAdapter(wrappedAdapter);
// Add the view pager to the header container
headerContainer.addView(mViewPager);
// add the container as a header view to the list
list.addHeaderView(headerContainer);
}
In the loadNewsFeed() method, I do an async fetch of the news feed items and populate the list by adding the items into the footer view. I won't go into the implementation details for this - outside the scope of this question.
The NewsFragment contains my pager adapter, which contains the getItem method that initializes the Fragment to be displayed by the ViewPager:
private class HeaderPagerAdapter extends FragmentPagerAdapter
{
public HeaderPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int i) {
return DateFragment.newInstance(i);
}
#Override
public int getCount() {
return Integer.MAX_VALUE;
}
}
And here is the actual Fragment to be displayed inside the ViewPager:
public class DateFragment extends Fragment
{
private int index;
TextView date;
public static final DateFragment newInstance(int index) {
DateFragment fragment = new DateFragment();
final Bundle args = new Bundle(1);
args.putInt(Constants.Extras.PAGE_INDEX, index);
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
index = getArguments() != null ? getArguments().getInt(Constants.Extras.PAGE_INDEX) : 1;
}
#Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState)
{
View v = (ViewGroup) inflater.inflate(R.layout.summary_fragment, container, false);
date = (TextView) v.findViewById(R.id.tvDate);
return v;
}
#Override
public void onActivityCreated(final Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
date.setText("Date: " + index);
}
}
For now I am simply using the index to be displayed as the date. I want to replace this with the actual date. Why does the fragment disappear on swipe?
Considerations:
Is there a refresh/redraw event that gets called?
Does it have to do with extending FragmentPagerAdapter vs. FragmentStatePagerAdapter
Override destroyItem() or instantiateItem()?
Set up a onPageScrolled listener on the ViewPager and then handle the page scroll events? I tried thehayro.blogspot.com/2012/12/enable-infinite-paging-with-android.html and that causes my fragments to disappear and then appear after a while.
Is it because I am adding the ViewPager as a header to the list view? The list view scrolls up and down and the view pager left and right. I've added this to my ViewPager implementation to tell the list view to stop intercepting our touch events:
#Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
// Tell our parent to stop intercepting our events!
boolean ret = super.onInterceptTouchEvent(ev);
if (ret)
{
getParent().requestDisallowInterceptTouchEvent(true);
}
return ret;
}
I'm sorry about the length of this post. I felt this much detail might be necessary. Thoughts?
I have a DataGrid, and I set a column with TextButtonCell.
If nothing is selected, everything is fine.
But once I select a row, the text on the button disappears.
How can I stop the text on the button disappearing?
Edit
Below is the code I created this button column:
Column<Publication, String> buttonColumn =
new Column<Publication, String>(new TextButtonCell()) {
#Override
public String getValue(Publication pub) {
((TextButtonCell)getCell()).setEnabled(pub.isPublishable());
return "Publish";
}
};
buttonColumn.setFieldUpdater(new FieldUpdater<Publication, String>() {
#Override
public void update(int index, Publication pub, String value) {
publish(pub);
}
});
pubDG.addColumn(buttonColumn);
Do not use selection model if possible. May be it will solve your problem
If you wat to use selection model then override the css to change the color of text of selected row then you will be able to see the text of text button.
I use Spinner in Dialog Mode.
I set SimpleCursorAdapter for the Spinner with setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
That works fine.
Now instead of simple_spinner_dropdown_item I'm trying to pass my custom layout it does work well too.
But there is a but... it does not have radio button that original simple_spinner_dropdown_item does.
Is it possible to add radio button inside of my custom spinner_dropdown_item that would be selected when spinner dialog is shown?
yes its possible but you have to define a another class for spinner.Just look at this
you have one more option to get your requirement. that is Alert dialog
just check out this Alert Dialog Window with radio buttons in Android and How to create custom and drop down type dialog and Dialog in android
Well I have found solution. ListView (what is inside of the spinners dialog) will check if your View is Checkable and call setChecked. Since android.R.layout.simple_spinner_dropdown_item is checkable it works.
So for my custom List item i have created LinearLayout that implements Checkable
public class CheckableLinearLayout extends LinearLayout implements Checkable
{
private boolean _isChecked = false;
public CheckableLinearLayout(Context context)
{
super(context);
}
public CheckableLinearLayout(Context context, AttributeSet attrs)
{
super(context, attrs);
}
#Override
public void setChecked(boolean checked)
{
_isChecked = checked;
for (int i = 0; i < getChildCount(); i++)
{
View child = getChildAt(i);
if (child instanceof Checkable)
{
((Checkable) child).setChecked(_isChecked);
}
}
}
#Override
public boolean isChecked()
{
return _isChecked;
}
#Override
public void toggle()
{
_isChecked = !_isChecked;
}
}
So ListView calls setChecked and I propagate that down to children views and my CheckBox / RadioButton will get checked / unchecked correctly.