Hello i am doing a little web scraping project to learn in android studio.
What my app does Right now is that it ask you to fill a field with a query then when you push a button it takes your query and it changes to a new view and searches in that page all possible instances of it and changes to a new view and shows you the information, right until this point i got it, now the problem is to show the results and how to do it because with just 1 result it shows the info with 0 problems but i want to show more than 1 results. so it shows
This image but one bellow the other until there are no more results
Here is the layout code that i want to put in a for loop
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
tools:context=".HomeActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/imgViewEbay"
android:scaleType="fitCenter"
android:layout_width="match_parent"
android:layout_height="200dp"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textStyle="bold"
android:layout_weight="3"
android:text="Nombre"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_weight="1"
android:id="#+id/txtTitleEbay"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textStyle="bold"
android:layout_weight="3"
android:text="Precio"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_weight="1"
android:textColor="#color/design_default_color_on_primary"
android:id="#+id/txtPrecioEbay"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textStyle="bold"
android:layout_weight="3"
android:text="Localizacion"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_weight="1"
android:textColor="#color/design_default_color_on_primary"
android:id="#+id/txtlocaEbay"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textStyle="bold"
android:layout_weight="3"
android:text="Tipos de pago"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_weight="1"
android:textColor="#color/design_default_color_on_primary"
android:id="#+id/txtpagoebay"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textStyle="bold"
android:layout_weight="3"
android:text="Condition"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_weight="1"
android:id="#+id/txtDescripcionebay"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textStyle="bold"
android:layout_weight="3"
android:text="Tiempo"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_weight="1"
android:textColor="#color/design_default_color_on_primary"
android:id="#+id/txttiempoEbay"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txtRatingebay"
android:gravity="center"
android:textStyle="bold"
android:layout_weight="3"
android:text="4.5"
android:textSize="28sp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RatingBar
style="#style/Widget.AppCompat.RatingBar.Indicator"
android:id="#+id/rating_barebay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btnbackebay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="Volver" />
<Button
android:id="#+id/btnLinkebay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="Link" />
</LinearLayout>
</LinearLayout>
</ScrollView>
And here is my attempt to do it :
```
Intent intent = getIntent();
String busqueda = intent.getStringExtra("busqueda");
final TextView txtitle = findViewById(R.id.txtTitleEbay);
final TextView txtprice = findViewById(R.id.txtPrecioEbay);
final ImageView img = findViewById(R.id.imgViewEbay);
final TextView txtlocation = findViewById(R.id.txtlocaEbay);
final TextView txtPayments = findViewById(R.id.txtpagoebay);
final RatingBar ratingBar = findViewById(R.id.rating_barebay);
final TextView txtRating = findViewById(R.id.txtRatingebay);
final TextView txtCondtion = findViewById(R.id.txtDescripcionebay);
final TextView txttime = findViewById(R.id.txttiempoEbay);
try {
for (int i = 0; i < buscadorebay(busqueda).length; i++) {
String url= buscadorebay(busqueda)[i];
new Thread(new Runnable()
{
final EbayProduct product = new EbayProduct();
#Override
public void run()
{
try
{
Document doc = Jsoup.connect(url)
.timeout(6000).get();
Elements image = doc.select("#icImg");
Elements title = doc.select("#vi-lkhdr-itmTitl");
Elements price = doc.select("#vi-mskumap-none #prcIsum");
Elements location = doc.select("#SRPSection [class='ux-textspans ux-textspans--SECONDARY']");
Elements payments = doc.select("#SRPSection [role='img']");
ArrayList<String> paymentMethods = new ArrayList<>();
for (Element payment : payments) {
paymentMethods.add(payment.attr("aria-label"));
}
Elements ratingEle = doc.select("#LeftSummaryPanel [itemprop='ratingValue']");
String ele = ratingEle.attr("content");
Elements condition1 = doc.select("#viTabs_0_is .ux-layout-section__row .ux-labels-values__values .ux-labels-values__values-content .ux-textspans");
Elements condtion2 = doc.select("#vi-desc-maincntr");
Elements Time = doc.select("#vi-cdown_timeLeft");
product.setTitle(title.text());
product.setImagUrl(image.attr("src"));
product.setPrice(price.text());
product.setLocation(location.text().replace("See detailsfor shipping Located in:", "").replace("See details- for more information about returns Learn moreLearn more about eBay global shipping program", ""));
product.setPayment(paymentMethods.toString());
product.setRating(Float.parseFloat(ratingEle.text()));
product.setCondition(condition1.text().replace(" Read moreabout the condition", "").replaceAll("[()]", "").replaceAll("[.]", ""));
product.setTime(Time.text());
}catch (Exception ex){}
runOnUiThread(new Runnable()
{
#Override
public void run()
{
txtitle.setText(product.getTitle());
Picasso.get()
.load(product.getImagUrl())
.into(img);
txtprice.setText(product.getPrice());
txtlocation.setText(product.getLocation());
txtPayments.setText(product.getPayment());
txtCondtion.setText(product.getCondition());
ratingBar.setRating(product.getRating());
txtRating.setText(product.getRating()+"");
txttime.setText(product.getTime());
}
});
}
}).start();
}} catch (IOException e) {
e.printStackTrace();
}
As you Can see i try to enter the view in a loop but i guess it is wrong since without the for loop and with just the normal url it goes without a problem. How then to make it so that it takes the info and then puts the views one below the other?
If you guys could help i would be thankful.
Related
Programmatically created TextViews aren't appearing when I run my app. I am trying to download messages and the person that sent them from Firebase and display them in separate TextViews with the sender TextView on top.
Sorry for the lack of information, but I don't know what I've done wrong.
db.collection("messagesIT")
.orderBy("Timesent", Query.Direction.DESCENDING)
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
#Override
public void onComplete(#NonNull Task<QuerySnapshot>task) {
if (task.isSuccessful()) {
ArrayList<MessageObj> messages = new ArrayList<>();
for (QueryDocumentSnapshot document : task.getResult())
String message = document.getString("Message");
String sender = document.getString("Sender");
Timestamp timesent = document.getTimestamp("Timesent");
MessageObj mess = new MessageObj(message, sender, timesent);
messages.add(mess);
Log.d(TAG, "m: " + mess.getMessage());
Log.d(TAG, "s: " + mess.getSender());
Log.d(TAG, "t:" + mess.getTimesent());
showToast("b");
}
TableLayout tl = findViewById(R.id.TableLayoutSubjectGroupPage);
//reading and displaying messages
for (int i = 0; i < messages.size(); i++) {
TableRow trMessage = new TableRow(SubjectGroupPage.this);
TableRow trSender = new TableRow(SubjectGroupPage.this);
TextView txtSender = new TextView(SubjectGroupPage.this);
TextView txtMessage = new TextView(SubjectGroupPage.this);
Log.d(TAG, "uv8iygv iyrtgcvfi8ytgvcrcccccccccccccccccccccccccccc");
LinearLayout.LayoutParams Weight = new LinearLayout.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT, 1);
txtSender.setText(messages.get(i).getSender());
txtSender.setLayoutParams(Weight);
txtMessage.setText(messages.get(i).getMessage());
txtMessage.setLayoutParams(Weight);
txtMessage.setTextSize(20);
txtMessage.setTextColor(Color.parseColor("#000000"));
if (messages.get(i).getSender().equals(currentUser.getUid())) {
txtMessage.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_END);
txtSender.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_END);
} else {
txtMessage.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
txtSender.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START);
}
//creating message display
trSender.addView(txtSender);
trMessage.addView(txtMessage);
tl.addView(trSender);
tl.addView(trMessage);
}
} else {
Log.d(TAG, "Error getting documents: ", task.getException());
}
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
showToast("There has been an error, please try again later.");
Log.d(TAG, "Error: " + e);
}
});
Layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:id="#+id/txtUsernameAdminStudentPage"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SubjectGroupPage">
<ScrollView
android:id="#+id/scrollviewMessages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="#+id/linearLayoutMessageInput"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<TableLayout
android:id="#+id/TableLayoutSubjectGroupPage"
android:layout_width="match_parent"
android:layout_height="wrap_content">
//these were tests for how I want the TextViews
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/txtExample"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView"
android:textColor="#000000"
android:textSize="20dp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView"
android:textAlignment="textEnd" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/txtExample2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView"
android:textAlignment="textEnd"
android:textColor="#000000"
android:textSize="20dp"
tools:layout_editor_absoluteY="675dp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView"
android:textAlignment="textEnd" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView"
android:textAlignment="textEnd"
android:textColor="#000000"
android:textSize="20dp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView"
android:textColor="#000000"
android:textSize="20sp" />
</TableRow>
</TableLayout>
</ScrollView>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
What the page looks like when run
What it should look like when run
Database
I think you forget to add layout params for table row.
BTW you should use recycler view with two view holders one for sender and 2nd for the receiver.
checkout if you want to improve your code
How to create RecyclerView with multiple view type?
or
https://medium.com/#droidbyme/android-recyclerview-with-multiple-view-type-multiple-view-holder-af798458763b
You explictly set the width of your TextViews to zero, using:
public LinearLayout.LayoutParams (int width, int height, float weight)
...where (see LinearLayout.LayoutParams):
int: the width, either ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT or a fixed size in pixels
MATCH_PARENT has a value of -1 and WRAP_CONTENT a value of -2. So this code sets a fixed width of 0:
LinearLayout.LayoutParams Weight = new LinearLayout.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT, 1)
Instead you should use:
TableLayout.LayoutParams tableParams_forRow = new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT);
and
TableRow.LayoutParams rowParams_forTextView = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
See this answer, for an example
And I set adapter to each CustomAutocompleteTextView. User select Entry type from the list of items. But if user enter that is not present in the list, I wanted to make that field empty.
For that I wrote code like this. It's Working fine. When I focus on next field this method is calling.
actvEntryCategory.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean b) {
String str = actvEntryCategory.getText().toString();
for (int i=0;i<EntryTypeAdapter.getCount();i++)
{
String temp = EntryTypeAdapter.getItem(i).toString();
if (str.compareTo(temp) == 0){
return;
}
}
actvEntryCategory.setText("");
// actvEntryCategory.setError("Please select valid Entry Type");
}
});
Now, user have to select Station Name from the list of Items, if not I wanted to make this field null.
For that I have written code like this. But this method is not calling when I focus on Next field.
actvDivName.setOnFocusChangeListener(new View.OnFocusChangeListener()
{
public void onFocusChange(View view, boolean b) {
try{
String str = actvDivName.getText().toString();
for (int i=0;i<QRDivArrayAdapter.getCount();i++)
{
String temp = QRDivArrayAdapter.getItem(i).toString();
if (str.compareTo(temp) == 0){
return;
}
}
actvDivName.setText("");
// actvEntryCategory.setError("Please select valid Entry Type");
}catch(Exception focusfordivision)
{
Log.d("eEmp/Resume", "Error raised due to " + focusfordivision.toString());
}
}
});
This is my XML code.
<LinearLayout
android:id="#+id/LLPlaceDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:weightSum="1">
<android.support.v7.widget.CardView
android:id="#+id/zone_card_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="#dimen/activity_horizontal_margin"
android:layout_marginLeft="#dimen/activity_custom_margin"
android:layout_marginRight="#dimen/activity_custom_margin"
android:layout_marginTop="#dimen/activity_horizontal_margin"
android:layout_weight="0.54"
card_view:cardElevation="#dimen/cardview_default_elevation"
card_view:contentPadding="10dp">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusableInTouchMode="false">
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_zone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="1">
<com.efftronics.android.eEmployee.Common.UI.CustomAutoCompleteTextView
android:id="#+id/actventry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="11"
android:hint="#string/Entry_Type"
android:inputType="textCapWords|textMultiLine"
android:maxLength="250"
android:theme="#style/AutocompleteTheme" />
</android.support.design.widget.TextInputLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_Division"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="1">
<com.efftronics.android.eEmployee.Common.UI.CustomAutoCompleteTextView
android:id="#+id/actvDivName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/station"
android:inputType="textCapWords|textMultiLine"
android:maxLength="250"
app:hintTextAppearance="#style/AutocompleteTheme"
/>
</android.support.design.widget.TextInputLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_ProductType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="1">
<com.efftronics.android.eEmployee.Common.UI.CustomAutoCompleteTextView
android:id="#+id/actvProductType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/product_type"
android:inputType="textCapWords|textMultiLine"
android:maxLength="250"
app:hintTextAppearance="#style/AutocompleteTheme" />
</android.support.design.widget.TextInputLayout>
</TableRow>
Why it is not calling?
Any help would be appreciated.
I have a List View thatis retrived from a php that get's it from MySql. However,when a retice the data that does not match the simple adater that I formated. Here is my code:
''HashMap map = new HashMap();
map.put(TAG_VALOR, valorIntent);
map.put(TAG_COMIDA , Scomida);
map.put(TAG_TABACO , Stabaco);
map.put(TAG_BEBIDAS , Sbebidas);
map.put(TAG_SABADO , Ssabado);
map.put(TAG_DOMINGO , Sdomingo);
map.put(TAG_HIGIROUP , Shigiroup);
map.put(TAG_MULTIBANCO , Smultibanco);
map.put(TAG_OUTROS , Soutros);
productsList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
ListAdapter adapter = new SimpleAdapter(
Relatorio.this, productsList,
R.layout.relatorio_details, new String[] { TAG_COMIDA,TAG_TABACO,TAG_BEBIDAS,TAG_SABADO
,TAG_DOMINGO,TAG_HIGIROUP, TAG_MULTIBANCO, TAG_OUTROS},
new int[] { R.id.comidaRel, R.id.tabacoRel,R.id.bebidasRel, R.id.sabadoRel
, R.id.domingoRel, R.id.higroupasRel, R.id.multibancoRel, R.id.outrosRel});
setListAdapter(adapter);
Log.d("Multibanco", TAG_MULTIBANCO);
}
});'
and this is the relatorio_details wrapped in LinearLayout vertical:
'<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Comida"/>
<TextView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/comidaRel"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Tabaco"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="#+id/tabacoRel"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Multibanco"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="#+id/multibancoRel"
android:text="0.00"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Bebidas"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="#+id/bebidasRel"
android:text="0.00"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Sábado"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="#+id/sabadoRel"
android:text="0.00"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Domingo"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="#+id/domingoRel"
android:text="0.00"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Higiene e Roupas"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="#+id/higroupasRel"
android:text="0.00"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1"
android:id="#+id/outros_rel">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Outros"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="#+id/outrosRel"
android:text="0.00"/>
</LinearLayout>
The data shows but does not respect the relatorio_details Layout
You need to make a custom adapter class for your list view nad a custom layout that is a simple xml layout file after that you need to set the adapter of your list view
ListView.setAdapter(new CustomAdapter(datalist));
Use this link for more help
Custom Adapter for List View
I just created an Activity to show some product informations and this Activity has a Collapsing Toolbar. I wanted to load an image by Picasso as soon as the Activity opens.
Here is the current code :
public class ProductActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_product);
Product p = (Product) getIntent().getExtras().getSerializable("product");
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setTitle(p.getProductName());
TextView name = (TextView) findViewById(R.id.product_name);
TextView type = (TextView) findViewById(R.id.product_type);
TextView description = (TextView) findViewById(R.id.product_description);
TextView ingredients = (TextView) findViewById(R.id.product_ingredients);
TextView price = (TextView) findViewById(R.id.product_price);
ImageView thumbnail = (ImageView) findViewById(R.id.product_thumbnail);
name.setText(p.getProductName());
type.setText(p.getProductType().getDisplayName());
description.setText(p.getProductDescription());
ingredients.setText("Non disponible");
price.setText(p.getProductPrice().length>1 ? "À partir de "+p.getProductPrice()[0].toString()+"€" : p.getProductPrice()[0].toString()+"€");
Picasso.with(this).load(p.getProductThumbnailURL()).fit().into(thumbnail);
Picasso.with(this).load(p.getProductThumbnailURL()).fit().into((ImageView)findViewById(R.id.test), new Callback() {
#Override
public void onSuccess() {
}
#Override
public void onError() {
Toast.makeText(ProductActivity.this, "Impossible de charger l'image !", Toast.LENGTH_SHORT).show();
}
});
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId()==android.R.id.home)finish();
return super.onOptionsItemSelected(item);
}
}
And here is a screen of the Activity (don't take care of the design xD)
ProductActivity
Any idea ? :p
Here is the XML file of the ProductActivity :
<android.support.design.widget.CoordinatorLayout
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"
tools:context="com.slama.hotpizza77.ProductActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<ImageView
android:id="#+id/product_thumbnail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
android:contentDescription="#string/product_thumbnail_string" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layoutManager="LinearLayoutManager"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="0dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="#+id/product_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="product_name"
style="#style/TextAppearance.AppCompat.Large"
tools:ignore="HardcodedText" />
<TextView
android:id="#+id/product_type"
style="#style/TextAppearance.AppCompat.Medium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="product_type"
android:textAppearance="#style/TextAppearance.AppCompat.Button"
tools:ignore="HardcodedText" />
<TextView
style="#style/TextAppearance.AppCompat.Body1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Description :"
android:textSize="18sp"
tools:ignore="HardcodedText" />
<TextView
android:id="#+id/product_description"
style="#style/TextAppearance.AppCompat.Small"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="product_description"
android:textSize="16sp"
tools:ignore="HardcodedText" />
<TextView
style="#style/TextAppearance.AppCompat.Body1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Ingrédients :"
android:textSize="18sp"
tools:ignore="HardcodedText" />
<TextView
android:id="#+id/product_ingredients"
style="#style/TextAppearance.AppCompat.Small"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="product_ingredients"
android:textSize="16sp"
tools:ignore="HardcodedText" />
<LinearLayout
android:layout_marginTop="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/ic_product_pork"/>
<TextView
android:layout_marginLeft="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Contient de la viande issue de porc !"
style="#style/TextAppearance.AppCompat.Body2"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/ic_product_notforkid"/>
<TextView
android:layout_marginLeft="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Ne convient pas aux enfants !"
style="#style/TextAppearance.AppCompat.Body2"/>
</LinearLayout>
<TextView
android:id="#+id/product_price"
android:layout_marginTop="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="product_price"
style="#style/Widget.AppCompat.Button.Colored"
tools:ignore="HardcodedText" />
<ImageView
android:id="#+id/test"
android:layout_width="match_parent"
android:layout_height="200dp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Instead of wrap_content for your product_thumbnail ImageView height use match_parent or a fixed size.
Hope this helps
I've set my buttons to be arranged from top to bottom in order of Facebook, Instagram, Twitter and Reddit but it's not doing that, it's only showing Facebook and Reddit and I don't know why.
I've got my buttons to automatically resize on Activity creation with this code:
public void getScreenRes() {
DisplayMetrics display = this.getResources().getDisplayMetrics();
int screenwidth = display.widthPixels;
int screenheight = display.heightPixels;
double buttonheight = screenwidth / 2.66666667;
int buttonheightint= (int) Math.round(buttonheight);
ImageButton fbLogin = (ImageButton) findViewById(R.id.facebookLogin);
ViewGroup.LayoutParams fb = fbLogin.getLayoutParams();
fb.width = screenwidth;
fb.height = buttonheightint;
fbLogin.setLayoutParams(fb);
ImageButton instaLogin = (ImageButton) findViewById(R.id.instagramLogin);
ViewGroup.LayoutParams insta = instaLogin.getLayoutParams();
insta.width = screenwidth;
insta.height = buttonheightint;
instaLogin.setLayoutParams(insta);
ImageButton twitLogin = (ImageButton) findViewById(R.id.twitterLogin);
ViewGroup.LayoutParams twit = instaLogin.getLayoutParams();
twit.width = screenwidth;
twit.height = buttonheightint;
twitLogin.setLayoutParams(twit);
ImageButton redditLogin = (ImageButton) findViewById(R.id.redditLogin);
ViewGroup.LayoutParams reddit = instaLogin.getLayoutParams();
reddit.width = screenwidth;
reddit.height = buttonheightint;
redditLogin.setLayoutParams(reddit);
}
XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="16dp"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.eren.valour.FirstTimeLogin">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/getStarted"
android:id="#+id/getStartedText"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:background="#drawable/facebook"
android:id="#+id/facebookLogin"
android:onClick="facebookLogin"
/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/instagram"
android:layout_below="#+id/facebookLogin"
android:id="#+id/instagramLogin"
android:onClick="instagramLogin"
/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/twitter"
android:layout_below="#+id/instagramLogin"
android:id="#+id/twitterLogin"
android:onClick="twitterLogin"
/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/reddit"
android:layout_below="#+id/twitterLogin"
android:id="#+id/redditLogin"
android:onClick="redditLogin"
/>
What it looks like now:
You need to get the corresponding Layoutparams.
ViewGroup.LayoutParams reddit = instaLogin.getLayoutParams();
should be
ViewGroup.LayoutParams reddit = redditLogin.getLayoutParams();
the same with the Twitter Login:
ViewGroup.LayoutParams twit = twitLogin.getLayoutParams();
What youre doing is taking the instagram layoutparams and applying it to 3 buttons so they all get placed on top of another, so only the last shows. Probably just a copy+past error on your side, but that should fix it.
If that does not fix it, the problem should be in the layout file. Try using a LinearLayout or setting the correct attributes for your RelativeLayout.
Try to change your Layout from RelativLayout to LinearLayout. That should do it.
You can put it into a LinearLayout with a weightsum Like so. Without the java method.
<LinearLayout 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:orientation="vertical"
android:paddingTop="16dp" android:weightSum="5"
tools:context="com.eren.valour.FirstTimeLogin">
<TextView
android:id="#+id/getStartedText" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" android:layout_weight="1" android:padding="50dp" // you can tweak this figure here
android:text="getStarted\nhere" android:textAppearance="?android:attr/textAppearanceLarge"/>
<ImageButton
android:id="#+id/facebookLogin" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_weight="1"
android:background="#drawable/fb" android:onClick="facebookLogin"/>
<ImageButton
android:id="#+id/instagramLogin" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_weight="1"
android:background="#drawable/insta" android:onClick="instagramLogin"/>
<ImageButton
android:id="#+id/twitterLogin" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_weight="1"
android:background="#drawable/twit" android:onClick="twitterLogin"/>
<ImageButton
android:id="#+id/redditLogin" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_weight="1"
android:background="#drawable/reddit" android:onClick="redditLogin"/>
</LinearLayout>
Update your XMl..
Instead of RelativeLayout ,I Think you should you should use LinearLayout and Weight propert like this ...
<LineaLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="16dp"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.eren.valour.FirstTimeLogin"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/getStarted"
android:id="#+id/getStartedText"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_weight="1"
/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="100dp"
android:background="#drawable/facebook"
android:id="#+id/facebookLogin"
android:onClick="facebookLogin"
android:layout_weight="1"
/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/instagram"
android:layout_below="#+id/facebookLogin"
android:id="#+id/instagramLogin"
android:onClick="instagramLogin"
android:layout_weight="1"
/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/twitter"
android:layout_below="#+id/instagramLogin"
android:id="#+id/twitterLogin"
android:onClick="twitterLogin"
android:layout_weight="1"
/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/reddit"
android:layout_below="#+id/twitterLogin"
android:id="#+id/redditLogin"
android:onClick="redditLogin"
android:layout_weight="1"
/>
Also you don't need this method getScreenRes() anymore.