I have a form that when this form is submitted, I want to disable my textedit, would you please help me in this implementation,
Thanks in advance!
Here is part of my class that submitted button is:
public class MyForm extends PreferenceGroup implements View.OnClickListener {
if (isFormSubmited) {
submitter.disable();
FormField.buttonCatchButton.setText("View");
updateForm();
}
my button for disable the editTex
private void disable(ViewGroup layout) {
layout.setEnabled(false);
for (int i = 0; i < layout.getChildCount(); i++) {
View child = layout.getChildAt(i);
if (child instanceof ViewGroup) {
disable((ViewGroup) child);
} else {
child.setEnabled(false);
}
}
}
my onclick method in another class
public void onClick(View v) {
FormFragment formFragment = new FormFragment();
Bundle bundle = new Bundle();
bundle.putString(Constants_Args.ITEMS_KEY, itemsKey);
if (catchFormFile != null) {
bundle.putString(Constants_Args.CATCH_FORM_FILE_PATH, catchFormFile.getAbsolutePath());
}
if (catchFormJSONObject != null) {
bundle.putString(Constants_Args.CATCH_FORM_JSONOBJECT, catchFormJSONObject.toString());
}
if (catchSpeciesJSONArray != null) {
bundle.putString(Constants_Args.CATCH_SPECIES_JSONARRAY, catchSpeciesJSONArray.toString());
}
catchFormFragment.setArguments(bundle);
MainActivity mainActivity = (MainActivity)getContext();
mainActivity.pushFragment(formFragment);
}
My problem is that I don't know how to set: If form submitted, formFragment needs to let its child views that the field is disabled
Related
I have Two Activity ( Activity A, Activity B) In Activity A i have a EditText,Button and Image View And in Activity B i have a Listview and the listView View Contain CustomXml with ImageView,TextView,and Another TextView
in Activity A, i enter List Name in Edit Text (Ex : Apple) and i Chose One Image ina GridView (Ex an Apple Image )
and i pass Both the Edittext and ImageView to a new Activity Where i want to Display Those names in ListView (Apple and Apple Image) How to DO that
i want to display something like this ( i get the Grocery List and Image From the Previous Activity and i want to display in ListView( in listview i extra add the items Count TEXTVIEW)
firstActivity.Java
done.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String itemname = listname.getText().toString();
if (!TextUtils.isEmpty(listname.getText().toString())) {
startActivity(new Intent(getContext(), CheckslateHome.class).putExtra("data", itemname).putExtra("image", imageRes));
dismiss();
} else {
Toast.makeText(getContext(), "List Name not Empty ", Toast.LENGTH_SHORT).show();
}
}
});
Second Activity
public class CheckslateHome extends AppCompatActivity {
TextView listcounts;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_checkslate_home);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
String itemName= bundle.getString("data");
Int ItemImage = bundle.getString("Image");
**//How to Pass these Intents into the Custom ListView**
}
listcounts = findViewById(R.id.list_count);
ListView listView = findViewById(R.id.list1);
CustomAdpter customAdapter = new CustomAdpter();
listView.setAdapter(customAdapter);
}
public class CustomAdpter extends BaseAdapter {
private Context context;
private LayoutInflater layoutInflater;
#Override
public int getCount() {
}
#Override
public Object getItem(int i) {
return null;
}
#Override
public long getItemId(int i) {
return 0;
}
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
if (view == null) {
view = layoutInflater.inflate(R.layout.rowlayout, viewGroup, false);
}
ImageView imageicons = view.findViewById(R.id.image_list);
TextView listnames = view.findViewById(R.id.list_name);
return view;
}
}
I Highly suggest using a combination of Fragments and navigation, in this way you can easily navigate through your app and send values between fragments using safe-args plugin
but if you persist on using activity, you should use startActivityForResult to call second activity.
I've spent a large amount of time trying to solve this issue both by myself and searching through here to find a solution, none of which have worked for me.
My current scenario is when a popup window appears I want to disable all clickable events on the foreground view which is underneath the popup window.
if (Shared.InspectionData.JobViewModel.RAMS_Id == null || Shared.InspectionData.JobViewModel.RAMS_Id.equals("")) {
// Disable foreground view here
LoadRAMSPopup();
}
private void LoadRAMSPopup() {
mainLayout.getForeground().setAlpha(150);
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final View ramsView = layoutInflater.inflate(R.layout.popup_rams, null);
final PopupWindow popupRAMS = new PopupWindow(
ramsView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
);
if (Build.VERSION.SDK_INT >= 21) {
popupRAMS.setElevation(5.0f);
}
findViewById(R.id.mainLayout).post(new Runnable() {
#Override
public void run() {
popupRAMS.showAtLocation(findViewById(R.id.mainLayout), Gravity.CENTER, 0, 0);
popupRAMS.setOutsideTouchable(false);
popupRAMS.update();
Button btnGenerate = (Button) ramsView.findViewById(R.id.btnGenerate);
btnGenerate.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), CreateRAMSActivity.class);
startActivity(intent);
popupRAMS.dismiss();
mainLayout.getForeground().setAlpha(0);
}
});
}
});
}
Hitchhiking off of Akshay Mukadam Disabling all child views inside the layout. I've tweaked it slightly to include enabling my views.
public static void disableEnableViews(ViewGroup layout) {
layout.setEnabled(false);
for (int i = 0; i < layout.getChildCount(); i++) {
View child = layout.getChildAt(i);
if (child instanceof ViewGroup) {
disableEnableViews((ViewGroup) child);
} else {
if(child.isEnabled()){
child.setEnabled(false);
} else {
child.setEnabled(true);
}
}
}
}
Simply give your top view an id, reference it, and then put into the method.
I am trying to populate data in UI fetched through REST service. The data comes up everytime but the UI doesn't get populated sometimes. The UI is kind of listing but listview is not being used. There's a ScrollView which has LinearLayout as its child and then row views are added to the linearlayout. There are times when UI just doesn't get updated even if the data is passed to it.
private void showData(List list) {
if(list != null && list.isEmpty()) {
mNoData.setVisibility(View.VISIBLE);
} else {
mNoData.setVisibility(View.GONE);
final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.details_layout);
findViewById(R.id.details_progress).setVisibility(View.GONE);
linearLayout.removeAllViews();
LayoutInflater layoutInflater = getLayoutInflater();
View rowView = null;
TextView txtName = null;
Button buttonPlay = null;
for (int i = 0; i < list.size(); i++) {
rowView = layoutInflater.inflate(R.layout.row_view, null);
txtName = (TextView) rowView.findViewById(R.id.row_view_name);
buttonPlay = (Button) rowView.findViewById(R.id.row_view_button_play);
final Item item = (Item) list.get(i);
rowView.setTag(i) ;
txtName.setText(item.getName());
final RecentItem recentItem = RecentsManager.getInstance().getRecentItemFromRefID(item.getId());
if (recentItem !=null) {
buttonPlay.setText(getString("Resume"));
buttonPlay.requestFocus();
}
buttonPlay.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (recentItem!=null) {
//do some action
} else {
//do some action
}
finish();
}
});
final int tag = (Integer) rowView.getTag() ;
rowView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//do some action
}
}) ;
txtName.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//do some action
}
});
buttonPlay.setId(i);
if(i < list.size())
buttonPlay.setNextFocusDownId(i+1);
linearLayout.addView(rowView);
if (i == 0) {
buttonPlay.requestFocus();
buttonPlay.setNextFocusUpId(mButtonReminder.getId());
if(mButtonReminder != null) {
mButtonReminder.setNextFocusDownId(buttonPlay.getId());
}
} else {
buttonPlay.setNextFocusUpId(i-1);
}
}
}
}
I have even checked the linearlayout children's count and the count is always equal to list size which means rows are also being added to it but it just doesn't show up on the UI.
What can be the issue?
you are using condition
if(list != null && list.isEmpty()) {
mNoData.setVisibility(View.VISIBLE);
}
change it to
if(list == null || list.isEmpty()) {
mNoData.setVisibility(View.VISIBLE);
}
I was able to resolve the issue by doing certain changes as adding fillViewPort="true" for scrollview. Also, there was a background thread which was trying to update the UI because of which UI thread was breaking. This didn't resulted in a crash but the UI updation didn't happened. With these two changes it's working fine.
I have a ListView and a custom adapter. When the user changes the sort type from a spinner, I want to redraw the list with the new items. The problem is that the ListView is re-drawn only after I interact with it on the device (start scrolling for example).
if (update) {
mOfferList = (ArrayList<PositionSearchItem>) psr
.getPositionSearchItem();
mAdapter.clear();
mAdapter.addAll(mOfferList);
mAdapter.notifydataSetChanged()
mList.invalidate();
mList.invalidateViews();
}
I have also tried to fully reset a new instance of my adapter to the list, it is giving the same result except that the list becomes blank at first and appears on user interaction.
I'm using HoloEveryWhere maybe this is an important info.
EDIT : Here is some more code
#EFragment(R.layout.list_fragment_results)
public class ResultsListFragment extends Fragment {
#ViewById(R.id.search_results_list)
ListView mList;
#ViewById(R.id.search_result_list_spinner)
Spinner mSpinner;
MainActivity mActivity;
private String mTypedText;
private List<String> mSortType;
private ResultsListFragment mFrag;
private Bundle mOffersPageBundle;
private SearchResultsListAdapter mAdapter;
private ArrayList<PositionSearchItem> mOfferList;
#AfterViews
public void afterViews() {
mFrag = this;
mActivity = (MainActivity) getActivity();
mSortType = new ArrayList<String>();
mSortType.add(SearchResultSortType.SCORE_DESCENDING);
mOfferList = new ArrayList<PositionSearchItem>();
mOffersPageBundle = getArguments();
PositionSearchResponse psr = mOffersPageBundle.getParcelable("offers");
mTypedText = mOffersPageBundle.getString("typedText");
mOfferList = (ArrayList<PositionSearchItem>) psr.getPositionSearchItem();
mAdapter = new SearchResultsListAdapter(this,
android.R.layout.simple_list_item_1, mOfferList, mTypedText,
mSortType, mActivity.getLat(), mActivity.getLon());
mList.setAdapter(mAdapter);
this.setListeners();
}
private void setListeners() {
mSpinner.setOnItemSelectedListener(new org.holoeverywhere.widget.AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(
org.holoeverywhere.widget.AdapterView<?> parent, View view,
int pos, long id) {
Boolean update = false;
PositionSearchResponse psr = null;
switch (pos) {
case 0:
if (mSortType.get(0) != SearchResultSortType.SCORE_DESCENDING) {
mSortType.clear();
mSortType.add(SearchResultSortType.SCORE_DESCENDING);
psr = processSearch(mTypedText, mSortType, 0, mActivity);
update = true;
}
break;
case 1:
if (mSortType.get(0) != SearchResultSortType.DATE) {
mSortType.clear();
mSortType.add(SearchResultSortType.DATE);
psr = processSearch(mTypedText, mSortType, 0, mActivity);
update = true;
}
break;
default:
break;
}
if (update) {
mOffersPageBundle.putParcelable("offers", psr);
mOfferList = (ArrayList<PositionSearchItem>) psr
.getPositionSearchItem();
mAdapter.mIdMap.clear();
for (int i = 0; i < mOfferList.size(); ++i) {
mAdapter.mIdMap.put(mOfferList.get(i), i);
}
mOfferList = (ArrayList<PositionSearchItem>) psr
.getPositionSearchItem();
mAdapter.clear();
mAdapter.addAll(mOfferList);
mAdapter.notifydataSetChanged()
mList.invalidate();
mList.invalidateViews();
}
}
#Override
public void onNothingSelected(
org.holoeverywhere.widget.AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
}
}
EDIT : the getView method from custom adapter
#Override
public View getView(int pos, View convertView, ViewGroup parent) {
this.v = convertView;
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
PositionSearchItem psr = getItem(pos);
v = vi.inflate(R.layout.result_list_item, parent, false);
v.setTag(pos);
// Inject text into view
((TextView) v.findViewById(R.id.result_title_textview))
.setText(getItem(pos).getTitle());
// Disable hardware acceleration for the view (it brakes dotted lines on
// some devices)
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
v.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
// reload list if scrolled to bottom
int page = 0;
if (pos > mLastViewed && pos == getCount() - 1) {
mLastViewed = pos;
ResultsListFragment frag = new ResultsListFragment_();
PositionSearchResponse newSearch = frag.processSearch(mTypedText, mSortType, mPage,
mActivity);
mPage = mPage + 12;
if(newSearch != null && newSearch.getPositionSearchItem() != null && newSearch.getPositionSearchItem().size() > 0){
for (int i = 0; i < newSearch.getPositionSearchItem().size(); ++i) {
mIdMap.put(newSearch.getPositionSearchItem().get(i), i);
}
this.addAll(newSearch.getPositionSearchItem());
}
}
return v;
}
Use
if (update) {
mAdapter.NotifyDataSetChanged();
}
this may solve your problem.
Try to set the adatpter again.Place the below code in all the places you wrote the code to update listview
mAdapter = new YourAdapter();
mList.setAdapet(mAdapter)
I hope you have created custom list view using adapter and model.
Now each time when you need to update your list view dynamically then you need to clear your previously created list view. Then after you need to fetch all new values and then update same over custom list view.
Hope it helps!
I need a method to get the information if my View is an instance of Button.
MyButton is a subclass of Button.
public void onCreate(Bundle s)
{
...
MyButton button = new MyButton(activity);
getViewType(button);
}
private <V extends View> V getViewClass(V view)
{
Class<V> clazz = (Class<T>) view.getClass();
if (clazz instanceof Button) {
return Button.class; //the information I need to get
}
}
The instanceof is not working here.
I can just compare clazz with Classes like you can see below. But I need the information if this view instance is a child of the class Button.
if (clazz == Button.class) ... //returns false
if (clazz == MyButton.class) ... //returns true
EDIT:
I got it. Solution:
if (Button.class.isAssignableFrom(clazz))
{
...
}
Why not just do this?
private <V extends View> V getViewClass(V view)
{
if (view instanceof Button) {
return Button.class; //the information I need to get
}
}