I am having some issues with the android Spinner. Please have a look at the below codes.
talk_settings.xml
<?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" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="17dp"
android:text="#string/language_locale"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/language_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_toRightOf="#+id/textView1"
android:layout_alignBaseline="#+id/textView1"
android:entries="#array/locale_arrays"
android:prompt="#string/locate_prompt"/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/spinner1"
android:layout_marginTop="37dp"
android:text="#string/pitch"
android:textAppearance="?android:attr/textAppearanceMedium" />
<SeekBar
android:id="#+id/pitchBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_marginTop="16dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/pitchBar"
android:layout_marginTop="27dp"
android:text="#string/speed"
android:textAppearance="?android:attr/textAppearanceMedium" />
<SeekBar
android:id="#+id/speedBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView3"
android:layout_marginTop="18dp" />
</RelativeLayout>
locale_string.xml (string resources for the spinner)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="locate_prompt">Select Language</string>
<string-array name = "locale_arrays">
<item>English</item>
<item>Chinese</item>
<item>French</item>
<item>Germany</item>
<item>Italian</item>
<item>Japanese</item>
<item>Korean</item>
</string-array>
</resources>
Java Code
//Event Handler for the language spinner
private class LanguageSpinnerHandler implements OnItemSelectedListener
{
int result = 0;;
#Override
public void onItemSelected(AdapterView<?> parent, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
if(parent.getItemAtPosition(position).toString()=="English")
{
result = tts.setLanguage(Locale.UK);
}
else if(parent.getItemAtPosition(position).toString()=="Chinese")
{
result = tts.setLanguage(Locale.CHINESE);
}
else if(parent.getItemAtPosition(position).toString()=="French")
{
result = tts.setLanguage(Locale.FRENCH);
}
else if(parent.getItemAtPosition(position).toString()=="Germany")
{
result = tts.setLanguage(Locale.GERMANY);
}
else if(parent.getItemAtPosition(position).toString()=="Italian")
{
result = tts.setLanguage(Locale.ITALIAN);
}
else if(parent.getItemAtPosition(position).toString()=="Japanese")
{
result = tts.setLanguage(Locale.JAPANESE);
}
else
{
result = tts.setLanguage(Locale.KOREAN);
}
if(result==TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED)
{
Toast.makeText(Talk.this, "This Language is Not Supported in Your Device", Toast.LENGTH_LONG).show();
tts.setLanguage(Locale.UK);
}
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
//show settings
private void showSettings()
{
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.talk_settings);
dialog.setTitle("Settings");
dialog.setCancelable(true);
SeekBar pitchBar = (SeekBar)dialog.findViewById(R.id.pitchBar);
SeekBar speakingSpeedBar = (SeekBar)dialog.findViewById(R.id.speedBar);
pitchBar.setProgress((int) pitchValue);
speakingSpeedBar.setProgress((int)speakingSpeedValue);
pitchBar.setOnSeekBarChangeListener(new PicthBarEvent());
speakingSpeedBar.setOnSeekBarChangeListener(new SpeakingSpeedBarEvent());
Spinner languageSpinner = (Spinner)findViewById(R.id.language_spinner);
languageSpinner.setOnItemSelectedListener(new LanguageSpinnerHandler());
dialog.show();
}
I am getting a NullPointerException right in here
languageSpinner.setOnItemSelectedListener(new LanguageSpinnerHandler());
Where I went wrong?
languageSpinner belongs to talk_settings.xml, so you have to look for it inside the dialog view
Spinner languageSpinner = (Spinner)dialog.findViewById(R.id.language_spinner);
also, String comparison in Java should be performed through the equals or equalsIgnoreCase method
Check if languageSpinner is initialized properly.
Spinner languageSpinner = (Spinner)dialog.findViewById(R.id.language_spinner);
findViewById looks for a a view in the current inflated layout. So use the dialog object to initialize spinner
and use .equals to compare strings
parent.getItemAtPosition(position).toString().equals("English")
Try usion
Spinner languageSpinner = (Spinner)dialog.findViewById(R.id.language_spinner);
instead of
Spinner languageSpinner = (Spinner)findViewById(R.id.language_spinner);.
As your spinner is in the talk_settings XML you will need to find the Spinner id in the view in which the XML is inflated.
Related
My layout_xml code:
<?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:minHeight="#dimen/_350sdp"
android:maxHeight="#dimen/_500sdp"
android:orientation="vertical"
android:id="#+id/commentProblemScreenLL">
<ListView
android:id="#+id/commentProblemLV"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/commentProblemNotFound"
android:visibility="gone"
android:id="#+id/commentProblemNotFoundTV"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/_40sdp"
android:background="#drawable/side_nav_bar"
android:orientation="horizontal"
android:padding="#dimen/m1dp"
android:weightSum="1"
android:layout_alignParentBottom="true">
<EditText
android:id="#+id/commentEditTextET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.9"
android:background="#null"
android:hint="#string/comment_EditText"
android:padding="5dip"
android:textColor="#color/white"
android:textColorHint="#color/hintcolor" />
<ImageButton
android:id="#+id/commentSendTextIB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:layout_alignParentEnd="true"
android:background="#drawable/side_nav_bar"
android:paddingBottom="#dimen/_4sdp"
android:src="#drawable/cm_chat_send"
android:layout_alignParentRight="true"
android:paddingRight="#dimen/_10sdp"
android:layout_marginTop="#dimen/_5sdp"/>
</RelativeLayout>
</RelativeLayout>
Java code:-
private void showCommentDailog()
{
Log.d(TAG,"showCommentDailog enter()");
commentDialog = new BottomSheetDialog(getContext());
View view = ((ProblemsDetailActivity) getActivity()).getLayoutInflater().inflate(R.layout.commentproblemscreen, null);
commentDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
commentProblemLV = (ListView)view.findViewById(R.id.commentProblemLV);
TextView commentProblemNotFoundTV = (TextView)view.findViewById(R.id.commentProblemNotFoundTV);
EditText commentEditTextET = (EditText) view.findViewById(R.id.commentEditTextET);
ImageButton commentSendTextIB = (ImageButton)view.findViewById(R.id.commentSendTextIB);
if(commentDialog.getWindow() != null) {
commentDialog.getWindow().setGravity(Gravity.BOTTOM);
}
//call the function to show list of previous work
commentDialog.setContentView(view);
commentDialog.setCanceledOnTouchOutside(true);
commentDialog.show();
final BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from((View) view.getParent());
bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
#Override
public void onStateChanged(#NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_HIDDEN) {
commentDialog.dismiss();
}else{
if (newState != BottomSheetBehavior.STATE_EXPANDED) {
if(commentProblemLV != null && !listIsAtTop()){
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
}
}
}
#Override
public void onSlide(#NonNull View bottomSheet, float slideOffset) {
}
});
}
This code does not show the full layout in bottomsheetDailog. Please correct my code as it shows the full layout in bottomsheetDialog.
I want to open full layout in half screen with BottomSheetDialog.
here I should be given my java code also for bottomSheetDialog.
bottomsheetdailog will apear on clickof comment ImageView.
Setup
In my app I have a section that creates rows of data to be saved in a database. Each row is built from a textbox, number box then "set" into a listview for display. Later on the user can open a "plan" created before and review the data.
I created a listview, a custom layout for the display line and figured out how to add/display each new row. However, when I perform the open, I create a dialog to display the list for plans, user selects on and the rows should display. They do not. I trace through the code and I see the arraylist for the adapter being populated and I call the notifydatasetchanged, but the main listview remains empty.
I am not using a customer adapter class, but just the Simple adapter.
This is the beginning of the Activity. I am still learning android coding so I tend to use generic names as I learn.
public class TrackItEqMainActivity extends AppCompatActivity {
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
public int rowCount = 1;
private static final String eTAG = "Exception";
final Context context = this;
// global variables needed for processing the add gaits display
**private ListView lstGaits;
private ListAdapter adapter;
private ArrayList<HashMap<String, String>> mylist;**
// *****
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(eTAG, "onCreate Build");
setTitle(R.string.activityManagePlans);
setContentView(R.layout.activity_track_it_eq_build);
Toolbar mySecondaryToolbar = (Toolbar) findViewById(R.id.my_secondaryToolbar);
setSupportActionBar(mySecondaryToolbar);
setActivityBuildListeners();
// set the objects needed to handle the dynamic gaits list
ListView lstGaits = (ListView) findViewById(R.id.lstMyGaits);
mylist = new ArrayList<HashMap<String, String>>();
try {
adapter = new SimpleAdapter(this, mylist, R.layout.gaits_detail,
new String[] { "keyGait", "keyTime" }, new int[] {
R.id.txtdisplayGait, R.id.txtdisplayTime });
lstGaits.setAdapter(adapter);
} catch (Exception e) {
Log.i(eTAG, e.getMessage());
}
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
SO when a user taps a new button a set of controls appear allowing to select a gait and enter a time. They then tap on the set button and in the set onClick, I add the data to the internal array and display the custom layout on the screen.
private Button.OnClickListener onClick_btnSet = new OnClickListener() {
#Override
public void onClick(View v) {
Spinner spinner = (Spinner) findViewById(R.id.spinner_gaits);
TextView textGait = (TextView) spinner.getSelectedView();
String gtResult = textGait.getText().toString();
TextView txtTime = (TextView) findViewById(R.id.txtSelected);
String tmeResult = txtTime.getText().toString();
buildDisplayLine(true,gtResult,tmeResult);
txtTime.setText("");
spinner.requestFocus();
}
};
The function that builds the line and adds to the array is this:
private void buildDisplayLine(boolean isNew, String gait, String time) {
HashMap<String, String> map2 = new HashMap<String, String>();
map2.put("keyGait",gait); // put the col data in
map2.put("keyTime", time); // put the col data in
mylist.add(map2);
if (isNew) {
((BaseAdapter) (adapter)).notifyDataSetChanged();
}
}
All that works although a strange side effect is that the list will not display if the number keypad is visible. When I clear it off the list appears.
Ifa use wants to look at or change a plan they tap the open button. IT display a dialog box that shows a list of plans. Tap on a plan and all the elements should display:
private final ThreadLocal<OnClickListener> onClick_btnOpen = new ThreadLocal<OnClickListener>() {
#Override
protected OnClickListener initialValue() {
return new OnClickListener() {
#Override
public void onClick(View v) {
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.activity_track_it_eq_open_plan);
dialog.setTitle("Open Exercise Plan...");
Button diaCancelButton = (Button) dialog.findViewById(R.id.btnCancelOpen);
diaCancelButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
// get a list of files from the local app plans
final eqDatabaseService eqDB = new eqDatabaseService(context, 2);
ArrayList<HashMap<String,String>> allPlans = eqDB.getPlanList();
if (allPlans.isEmpty()) {
Toast toast = new Toast(context);
toast.setGravity(Gravity.TOP, 0, 0);
Toast.makeText(context, "No Files to open, Please create one!", Toast.LENGTH_LONG).show();
return;
}
ListView lvPlan = (ListView) dialog.findViewById(R.id.lvPlans);
try {
adapter = new SimpleAdapter(context, allPlans, R.layout.plans_columns,
new String[] { "keyName", "keyENum" }, new int[] {
R.id.txtPlanName, R.id.txtNumElements });
lvPlan.setAdapter(adapter);
} catch (Exception e) {
}
//********************************************************
lvPlan.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
TextView txtplan = (TextView) v.findViewById(R.id.txtPlanName);
String planName = txtplan.getText().toString();
List<eqSessions_dt> myPlan = eqDB.getCurrentPlan(planName);
clearGrid();
for (eqSessions_dt row : myPlan) {
buildDisplayLine(false, row.get_gait(),Integer.toString(row.get_time()));
}
((BaseAdapter)(adapter)).notifyDataSetChanged();
dialog.dismiss();
}
});
dialog.show();
}
};
}
};
I have played around with this, did look at other similar questions and answers, but didn't see anything that would explain why the notify would not work. I avoided doing a custom adapter, trying to keep this simple at first. What am I missing that stops the list from displaying. I see the arraylist being filled and all related objects are global to the activity. I'll keep playing around, but I hope otehr eyes see what I miss.
This is the activity xml`
<LinearLayout 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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
tools:context="com.newproject.jhull3341.trackiteq.TrackItEqMainActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/my_secondaryToolbar"
android:layout_width="fill_parent"
android:layout_height="?attr/actionBarSize"
android:background="#236dc1"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/lyFileAction">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="92dp"
android:layout_height="match_parent"
android:text="New"
android:id="#+id/btnNew"
android:layout_row="0"
android:layout_column="0"
android:layout_gravity="center_horizontal" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="92dp"
android:layout_height="match_parent"
android:text="Open"
android:id="#+id/btnOpen"
android:layout_row="0"
android:layout_column="1"
android:layout_gravity="center_horizontal" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="92dp"
android:layout_height="match_parent"
android:text="Save"
android:id="#+id/btnSave"
android:layout_row="0"
android:layout_column="2"
android:layout_gravity="center_horizontal" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="92dp"
android:layout_height="match_parent"
android:text="Delete"
android:id="#+id/btnDelete"
android:layout_row="0"
android:layout_column="3"
android:layout_gravity="center_horizontal" />
</GridLayout>
<GridLayout
android:layout_width="367dp"
android:layout_height="wrap_content"
android:id="#+id/grdEntry">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/label_time"
android:id="#+id/lblTime"
android:layout_row="0"
android:layout_column="1"
android:layout_marginBottom="5dp" />
<Spinner
android:layout_width="147dp"
android:layout_height="wrap_content"
android:id="#+id/spinner_gaits"
android:layout_row="1"
android:layout_column="0"
android:focusable="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/label_Gait"
android:id="#+id/lblGait"
android:layout_row="0"
android:layout_column="0"
android:layout_marginBottom="5dp" />
<EditText
android:layout_width="124dp"
android:layout_height="wrap_content"
android:id="#+id/txtSelected"
android:layout_row="1"
android:layout_column="1"
android:layout_gravity="fill_horizontal|center_vertical"
android:singleLine="true"
android:numeric="integer" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="92dp"
android:layout_height="fill_parent"
android:text="Set"
android:id="#+id/btnSet"
android:layout_row="1"
android:layout_column="2"
android:layout_gravity="center_vertical"
android:clickable="true" />
</GridLayout>
<ListView
android:id="#+id/lstMyGaits"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_below="#+id/grdEntry" />
</LinearLayout>
this is the custom layout for each display row.`
<?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="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/txtdisplayGait"
android:layout_width="wrap_content"
android:layout_height="44dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="TextView"
android:textSize="18sp" />
<TextView
android:id="#+id/txtdisplayTime"
android:layout_width="80dp"
android:layout_height="44dp"
android:gravity="center_vertical"
android:text="TextView"
android:textSize="18sp" />
<ImageButton
android:id="#+id/btnRemoveLine"
android:layout_width="25dp"
android:layout_height="44dp"
android:layout_weight="0.39"
android:background="#color/wallet_bright_foreground_holo_dark"
android:elevation="1dp"
android:src="#android:drawable/btn_dialog" />
</LinearLayout>`
I am experiencing a very weird issue where I am unable to view any text/data, but it clearly shows the number of items in the list.
I have confirmed that dataList has data, and I am able to get the exact same string that I set after debugging.
Parent Fragment:
ListView InboxListView = (ListView) view.findViewById(R.id.listViewInbox);
InboxAdapter adapter = new InboxAdapter(mActivity, R.layout.activity_inbox_item, dataList, NotificationInbox.this);
XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/SwipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="match_parent"
android:padding="15dp"
android:id="#+id/searchBarInbox"
android:hint="Search"
android:layout_height="wrap_content" />
<ListView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_marginTop="49dp"
android:id="#+id/listViewInbox" />
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>
Adapter: http://pastebin.com/mSUrdLcW << CLICK
public class InboxAdapter extends ArrayAdapter<InboxBO> {
NotificationInbox fragment;
Context context;
List<InboxBO> inboxForSharedPref;
List<InboxBO> inboxList;
int layoutResID;
SharedPreferences prefs;
private ArrayList<InboxBO> inboxarraylist;
private SparseBooleanArray mSelectedItemIds;
public InboxAdapter(Context context, int layoutResourceID, List<InboxBO> objs, NotificationInbox fragment) {
super(context, layoutResourceID, objs);
mSelectedItemIds = new SparseBooleanArray();
this.context = context;
this.inboxList = objs;
this.layoutResID = layoutResourceID;
this.inboxarraylist = new ArrayList<InboxBO>();
this.inboxarraylist.addAll(inboxList);
this.fragment = fragment;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
inboxHolder inboxholder;
View view = convertView;
if (view == null) {
view = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(layoutResID, parent, false);
//LayoutInflater inflater = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE));
//LayoutInflater inflater = LayoutInflater.from(getContext());
//inflater.inflate(R.layout.activity_inbox_item, null);
inboxholder = new inboxHolder();
//view = inflater.inflate(layoutResID, parent, false);
prefs = context.getSharedPreferences(
Constants.PREF_NAME, 0);
inboxholder.swipeLayout = (SwipeLayout)view.findViewById(R.id.swipe_layout);
inboxholder.senderNameText = (TextView) view.findViewById(R.id.senderNameText);
inboxholder.pushDateText = (TextView) view.findViewById(R.id.pushDateText);
inboxholder.pushTimeText = (TextView) view.findViewById(R.id.pushTimeText);
inboxholder.messageText = (TextView) view.findViewById(R.id.messageText);
inboxholder.delete = (TextView)view.findViewById(R.id.delete);
inboxholder.itemLayout = (RelativeLayout) view.findViewById(R.id.relativeViewInbox);
inboxholder.swipeLayout.setShowMode(SwipeLayout.ShowMode.PullOut);
inboxholder.delete.setOnClickListener(onDeleteListener(position, inboxholder));
view.setTag(inboxholder);
}
else {
inboxholder = (inboxHolder) view.getTag();
}
InboxBO mItem = inboxList.get(position);
if(mItem!=null){
inboxholder.senderNameText.setText((String)mItem.getTitle());
inboxholder.pushDateText.setText(new Date().toString());
inboxholder.pushTimeText.setText(new Date().toString());
inboxholder.messageText.setText((String)mItem.getMessage());
}
return view;
}
// For swipe action
private View.OnClickListener onDeleteListener(final int position, final inboxHolder holder) {
return new View.OnClickListener() {
#Override
public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(
context);
alert.setTitle("Delete Message");
alert.setMessage("Are you sure you wish to delete this message?");
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
inboxList.remove(position);
Gson gson = new Gson();
inboxForSharedPref = fragment.getStoredMessages();
inboxForSharedPref = inboxList;
String jsonSavePref = gson.toJson(inboxForSharedPref);
fragment.commitToStoredList(jsonSavePref);
Toast.makeText(context, "Message Deleted!",
Toast.LENGTH_SHORT).show();
holder.swipeLayout.close();
fragment.retrieveMessage();
dialog.dismiss();
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alert.show();
}
};
}
// Algorithm to filter out listview based on text changed in listview searchbox
public void filter(String charText) {
charText = charText.toLowerCase(Locale.getDefault());
inboxList.clear();
if (charText.length() == 0) {
inboxList.addAll(inboxarraylist);
}
else
{
for (InboxBO ilist : inboxarraylist)
{
/*if (ilist.getDate().toLowerCase(Locale.getDefault()).contains(charText) || ilist.getMessage().toLowerCase(Locale.getDefault()).contains(charText) || ilist.getSendername().toLowerCase(Locale.getDefault()).contains(charText))
{
inboxList.add(ilist);
}*/
if(ilist.getTitle().toLowerCase(Locale.getDefault()).contains(charText) || ilist.getMessage().toLowerCase(Locale.getDefault()).contains(charText) ){
inboxList.add(ilist);
}
}
}
notifyDataSetChanged();
}
public static class inboxHolder {
TextView senderNameText, pushDateText, pushTimeText, messageText, delete, title;
RelativeLayout itemLayout;
private SwipeLayout swipeLayout;
}
// Methods below are for multi-deletion
public void toggleSelection(int position) {
selectView(position, !mSelectedItemIds.get(position));
}
// Remove selection after unchecked
public void remove(InboxBO object) {
inboxList.remove(object);
Gson gson = new Gson();
inboxForSharedPref = fragment.getStoredMessages();
inboxForSharedPref = inboxList;
String jsonSavePref = gson.toJson(inboxForSharedPref);
fragment.commitToStoredList(jsonSavePref);
notifyDataSetChanged();
}
// Item checked on selection
public void selectView(int position, boolean value) {
if (value)
mSelectedItemIds.put(position, value);
else
mSelectedItemIds.delete(position);
notifyDataSetChanged();
}
// Get number of selected item
public int getSelectedCount() {
return mSelectedItemIds.size();
}
public SparseBooleanArray getSelectedIds() {
return mSelectedItemIds;
}
public void removeSelection() {
mSelectedItemIds = new SparseBooleanArray();
notifyDataSetChanged();
}
}
Adapter XML:
<?xml version="1.0" encoding="utf-8"?>
<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swipe_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/bottom_wrapper"
android:layout_width="100dp"
android:layout_gravity="start"
android:layout_height="match_parent"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ff0000">
<TextView
android:id="#+id/delete"
android:text="Delete"
android:textSize="18sp"
android:textColor="#color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:background="?android:attr/activatedBackgroundIndicator"
android:orientation="vertical"
android:layout_width="match_parent"
android:id="#+id/relativeViewInbox"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal"
android:id="#+id/linearLayout">
<TextView
android:layout_width="match_parent"
android:text="SenderName"
android:textColor="#color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="left"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="#+id/senderNameText"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:text="PushDate"
android:gravity="right"
android:textColor="#color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="#+id/pushDateText" />
</LinearLayout>
<TextView
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:text="Message..."
android:id="#+id/messageText"
android:textColor="#color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:ellipsize="end"
android:maxLines="1"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/linearLayout" />
<TextView
android:layout_width="match_parent"
android:text="PushTime"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="right"
android:layout_weight="1"
android:textColor="#color/black"
android:layout_height="match_parent"
android:id="#+id/pushTimeText"
android:layout_alignTop="#+id/messageText" />
</RelativeLayout>
</com.daimajia.swipe.SwipeLayout>
EDIT: Screenshot added
EDIT2: Clarified parent fragment calling the adapter.
EDIT3: I did a temporary fix. Apparently the RelativeLayout and the Linear Layout in the AdapterXML were the cause of my misery. I'm not exactly sure why, though. I think it's the RelativeLayout and the LinearLayout somehow not displaying the text. Removing those two tags will display the texts in a linear fashion.
Try this
Adapter XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/bottom_wrapper"
android:layout_width="100dp"
android:layout_gravity="start"
android:layout_height="match_parent"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ff0000">
<TextView
android:id="#+id/delete"
android:text="Delete"
android:textSize="18sp"
android:textColor="#color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:background="?android:attr/activatedBackgroundIndicator"
android:orientation="vertical"
android:layout_width="match_parent"
android:id="#+id/relativeViewInbox"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal"
android:id="#+id/linearLayout">
<TextView
android:layout_width="match_parent"
android:text="SenderName"
android:textColor="#color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="left"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="#+id/senderNameText"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:text="PushDate"
android:gravity="right"
android:textColor="#color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="#+id/pushDateText" />
</LinearLayout>
<TextView
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:text="Message..."
android:id="#+id/messageText"
android:textColor="#color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:ellipsize="end"
android:maxLines="1"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/linearLayout" />
<TextView
android:layout_width="match_parent"
android:text="PushTime"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="right"
android:layout_weight="1"
android:textColor="#color/black"
android:layout_height="match_parent"
android:id="#+id/pushTimeText"
android:layout_alignTop="#+id/messageText" />
</RelativeLayout>
I am trying to simply hide a linear layout if a checkbox is clicked. I have defined function and onClick attribute calls it which is also tested with toast but when I try hiding the layout, it doesn't do anything.
The layout.xml:
<CheckBox
android:id="#+id/cbguest"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.9"
android:onClick="itemClicked"
/>
In MainActivity.java
int[] i = {0};
public void itemClicked(View v) {
LinearLayout layoutguest1 = (LinearLayout) findViewById(R.id.guestlayout);
if (lns[0]%2 == 0) {
Toast.makeText(getApplicationContext(),"Visible", Toast.LENGTH_SHORT).show();
layoutguest1.setVisibility(View.VISIBLE);
lns[0]+=1;
}
if (lns[0]%2 != 0) {
layoutguest1.setVisibility(View.GONE);
Toast.makeText(getApplicationContext(),"Gone", Toast.LENGTH_SHORT).show();
lns[0]+=1;
}
}
**activity_main.xml
put this code in activity_main.xml file**
<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"
tools:context="com.example.demo.MainActivity" >
<LinearLayout
android:id="#+id/layoutLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UserName" />
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password" />
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<CheckBox
android:id="#+id/chkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Hide" />
</RelativeLayout>
**MainActivity.java
put this code in MainActivity.java file**
public class MainActivity extends Activity {
private LinearLayout layoutLogin;
private CheckBox chkBox;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
chkBox = (CheckBox) findViewById(R.id.chkBox);
layoutLogin = (LinearLayout) findViewById(R.id.layoutLogin);
chkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked)
{
// TODO Auto-generated method stub
if(isChecked)
{
layoutLogin.setVisibility(View.GONE);
chkBox.setText("UnHide");
}
else
{
layoutLogin.setVisibility(View.VISIBLE);
chkBox.setText("Hide");
}
}
});
}
}
You should be using onCheckedChangeListener as I don't think it registers as an onClick- but an onCheck.
Android: checkbox listener
Following some tutorials, I managed to make a custom list.
But the whole screen is just a list
And now want to put the list below the form. And to make the whole screen make scroll along with the list (see the last item in the list, the form needs to rise)
The log (Toasty) says that the item was added, but nothing appears. I do not know if the problem is in how I add, or is the way I try to display
This is my layout:
<?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="wrap_content"
android:background="#ffffff"
android:fillViewport="true"
android:padding="5dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/cliente" />
<EditText
android:id="#+id/venda_form_cliente"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cursorVisible="false"
android:focusable="false"
android:hint="#string/selecione_um_cliente" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/produto" />
<EditText
android:id="#+id/venda_form_prod"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:cursorVisible="false"
android:focusable="false"
android:hint="#string/selecione_um_produto" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/quantidade" />
<EditText
android:id="#+id/venda_form_qtd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:selectAllOnFocus="true"
android:text="#string/um" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/valor" />
<EditText
android:id="#+id/venda_form_valor"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cursorVisible="false"
android:focusable="false"
android:inputType="none" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/desconto" />
<EditText
android:id="#+id/venda_form_desc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:selectAllOnFocus="true"
android:text="#string/zero" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/subtotal" />
<EditText
android:id="#+id/venda_form_subtotal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cursorVisible="false"
android:focusable="false"
android:inputType="none" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/venda_form_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="10dp"
android:text="#string/adicionar" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="none" >
</ListView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
And my activity
public class VendaFormActivity extends Activity {
private Cliente cliente;
// private Spinner condicaoSelect;
private Produto produto;
private TextWatcher somar;
private ItemVenda itemVenda;
private ListaAdapter listaAdapter;
private EditText inputQuantidade;
private EditText inputDesconto;
private EditText inputSubTotal;
private EditText inputProduto;
private EditText inputValor;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_venda_form);
inputProduto = ((EditText) findViewById(R.id.venda_form_prod));
inputValor = ((EditText) findViewById(R.id.venda_form_valor));
((EditText) findViewById(R.id.venda_form_cliente)).setOnClickListener(new ClickListener(this, ClienteActivity.class, MainActivity.REQUEST_CLIENTE));
inputProduto.setOnClickListener(new ClickListener(this, ProdutoActivity.class, MainActivity.REQUEST_PRODUTO));
//condicaoSelect = (Spinner) findViewById(R.id.venda_form_condicao);
//new CondicaoHelper(this).popular(condicaoSelect);
bindCamposValores();
fazerLista();
bindBtnAdd();
}
private void limparCamposValores() {
inputDesconto.setText("0.00");
inputQuantidade.setText("1");
inputSubTotal.getText().clear();
inputProduto.getText().clear();
}
private void bindBtnAdd() {
((Button) findViewById(R.id.venda_form_btn)).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
try{
Double quantidade = Double.parseDouble( inputQuantidade.getText().toString() );
Double desconto = Double.parseDouble( inputDesconto.getText().toString() );
itemVenda = new ItemVenda();
itemVenda.setDesconto(desconto);
itemVenda.setProduto(produto);
itemVenda.setQuantidade(quantidade);
listaAdapter.setNotifyOnChange(true);
listaAdapter.getItens().add(itemVenda);
listaAdapter.notifyDataSetChanged();
Toast.makeText(getApplication(), "Foi", Toast.LENGTH_SHORT).show();
limparCamposValores();
} catch (Exception e) {
Toast.makeText(getApplication(), "Invalido", Toast.LENGTH_SHORT).show();
// NPE no produto
// NumberFormat nos valores
}
}
});
}
private void fazerLista() {
listaAdapter = new ListaAdapter(getApplicationContext());
((ListView) findViewById(android.R.id.list)).setAdapter(listaAdapter);
}
static class ViewHolder {
protected TextView descricao;
protected TextView codigo;
protected TextView ean;
protected TextView referencia;
protected TextView quantidade;
protected TextView valor_unit;
protected TextView valor_item;
}
private class ListaAdapter extends ArrayAdapter<ItemVenda>{
private final Context context;
private final List<ItemVenda> itens;
public ListaAdapter(Context context) {
super(context, R.layout.produto_list);
this.context = context;
this.itens = new LinkedList<ItemVenda>();
}
public ListaAdapter(Context context, List<ItemVenda> itens) {
super(context, R.layout.produto_list, itens);
this.context = context;
this.itens = itens;
}
public List<ItemVenda> getItens() {
return itens;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflator.inflate(R.layout.produto_list_item, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.descricao = (TextView) view.findViewById(R.id.descricao);
viewHolder.codigo = (TextView) view.findViewById(R.id.codigo);
viewHolder.ean = (TextView) view.findViewById(R.id.ean);
viewHolder.referencia = (TextView) view.findViewById(R.id.referencia);
viewHolder.quantidade = (TextView) view.findViewById(R.id.quantidade);
viewHolder.valor_unit = (TextView) view.findViewById(R.id.valor_unit);
viewHolder.valor_item = (TextView) view.findViewById(R.id.valor_item);
view.setTag(viewHolder);
} else {
view = convertView;
}
ViewHolder holder = (ViewHolder) view.getTag();
ItemVenda item = itens.get(position);
holder.descricao.setText(item.getProduto().getNome());
holder.codigo.setText(item.getProduto().getCodigo());
holder.ean.setText(item.getProduto().getEan());
holder.referencia.setText(item.getProduto().getReferencia());
holder.quantidade.setText(item.getQuantidade().toString());
holder.valor_unit.setText(item.getProduto().getPreco().toString());
holder.valor_item.setText(item.getSubTotal().toString());
return view;
}
}
private void bindCamposValores() {
inputQuantidade = ((EditText) findViewById(R.id.venda_form_qtd));
inputDesconto = ((EditText) findViewById(R.id.venda_form_desc));
inputSubTotal = ((EditText) findViewById(R.id.venda_form_subtotal));
somar = new TextWatcher() {
#Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { }
#Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { }
#Override
public void afterTextChanged(Editable arg0) {
Double sub = 0.0;
try{
itemVenda = new ItemVenda();
itemVenda.setQuantidade(Double.parseDouble(inputQuantidade.getText().toString()));
itemVenda.setDesconto(Double.parseDouble(inputDesconto.getText().toString()));
itemVenda.setProduto(produto);
sub = itemVenda.getSubTotal();
} catch (Exception e) {
// algum campo não é numero/está vazio
}
inputSubTotal.setText(""+sub);
}
};
// Se mudar o valor
inputQuantidade.addTextChangedListener(somar);
inputDesconto.addTextChangedListener(somar);
// quando sair do campo
inputQuantidade.setOnFocusChangeListener(new Focus("1"));
inputDesconto.setOnFocusChangeListener(new Focus("0.00"));
}
private class Focus implements OnFocusChangeListener {
private final String padrao;
public Focus(String padrao){
this.padrao = padrao;
}
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus){
Editable text = ((EditText) v).getText();
if(null == text || "".equals(text.toString())){
text.append(padrao);
}
}
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_venda_form, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.menu_copiar:
copiar();
return true;
case R.id.menu_simulacao:
simulacao();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void copiar() {
Toast.makeText(getApplication(), "Nada ainda", Toast.LENGTH_SHORT).show();
}
private void simulacao() {
Intent intent = new Intent(getApplicationContext(), SimulacaoPagtoActivity.class);
startActivityForResult(intent, MainActivity.REQUEST_SIMULACAO);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == MainActivity.REQUEST_CLIENTE) {
if (resultCode == RESULT_OK) {
cliente = (Cliente) intent.getSerializableExtra(MainActivity.RESULT_MODEL_LIST);
((EditText) findViewById(R.id.venda_form_cliente)).setText(cliente.getNome());
}
} else if (requestCode == MainActivity.REQUEST_PRODUTO) {
if (resultCode == RESULT_OK) {
produto = (Produto) intent.getSerializableExtra(MainActivity.RESULT_MODEL_LIST);
inputProduto.setText(produto.getNome());
inputValor.setText(""+produto.getPreco());
somar.afterTextChanged(null);
}
} else if(requestCode == MainActivity.REQUEST_SIMULACAO){
// o que fazer quando voltar da simulação ?
}
}
}
Finally, my item layout
<?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="wrap_content"
android:baselineAligned="false"
android:orientation="vertical"
android:padding="5dp" >
<TextView
android:id="#+id/descricao"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#333"
android:textSize="16sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/codigo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="CODIGO" />
<TextView
android:id="#+id/ean"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="EAN" />
<TextView
android:id="#+id/referencia"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="REFERENCIA" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/quantidade"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="QUANT." />
<TextView
android:id="#+id/valor_unit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="VLR UNIT" />
<TextView
android:id="#+id/valor_item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="VLR ITEM" />
</LinearLayout>
</LinearLayout>
UPDATE
When I add an item in the list, nothing is shown. But after I click a TextEdit, and the virtual keyboard up, after typing some value, I close the keyboard, then the adapter.getView () is called and the list appears
I think I found your problem. Shouldn't the following code:
((ListView) findViewById(android.R.id.list)).setAdapter(listaAdapter);
Be:
((ListView) findViewById(R.id.list)).setAdapter(listaAdapter);
instead?
You are trying to find a default Android view, rather than the view that you have created, which means that you are not actually setting the adapter for your ListView.
I am not sure about that, but if you want the list to be scrollable with the activity, you should use ScrollView, and then check if you scroll the list or the view itself. Try it
You can also try to see with debugger if the item was actually added to the list. I hope you will find an error.
Found the solution
1) The adapter have 2 constructors, but just 1 with List<ItemVenda> itens, and it isn't called.
I fixed it.
2) To add an item on the list, I need to call adapter.add() and not adapter.getItens().add()`. I think this trigger others methods.
3) Finally, to take the scroll list, and apply the scroll across the screen, I need to increase the size of the list. Then I override the method adapter.add(), and calculate the new height of the list, and add android:scrollbars="none" on ListView
Thanks to all, especially to #Marek