the app is used to sign up for events. Now I am unable to display more then one card in the recycler view even though there is data in the database.it only would display only the first row of data. I know this as I have deleted the first row and the app shows the new first row.
The php works as i have loaded the page and it gives me the data from the database.
recycler view activity
public class MainActivity2 extends AppCompatActivity {
private static final String URL = "http://10.0.2.2/mad/activitydisplay.php";
RecyclerView recyclerView;
UserAdapter userAdapter;
List<Users> usersList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
recyclerView = findViewById(R.id.recylcerList);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
usersList=new ArrayList<>();
LoadAllUser();
}
private void LoadAllUser() {
JsonArrayRequest request =new JsonArrayRequest(URL, new Response.Listener<JSONArray>() {
#Override
public void onResponse(JSONArray array) {
for (int i=0;i<array.length();i++){
try {
JSONObject object=array.getJSONObject(i);
String name=object.getString("eventname").trim();
String type=object.getString("type").trim();
String location=object.getString("location").trim();
String time=object.getString("time").trim();
String date=object.getString("date").trim();
String maxparticipants=object.getString("maxparticipants").trim();
Users user= new Users();
user.setName(name);
user.setType(type);
user.setLocation(location);
user.setTime(time);
user.setDate(date);
user.setMaxparticipants(maxparticipants);
usersList.add(user);
} catch (JSONException e) {
e.printStackTrace();
}
}
userAdapter=new UserAdapter(MainActivity2.this,usersList);
recyclerView.setAdapter(userAdapter);
}
},new Response.ErrorListener(){
#Override
public void onErrorResponse(VolleyError error){
Toast.makeText(MainActivity2.this, error.toString(), Toast.LENGTH_SHORT).show();
}
});
RequestQueue requestQueue=Volley.newRequestQueue(MainActivity2.this);
requestQueue.add(request);
}
}
recycler view adpater
public class UserAdapter extends RecyclerView.Adapter<UserAdapter.UserHolder>{
Context context;
List<Users> usersList;
public UserAdapter(Context context, List<Users> usersList) {
this.context = context;
this.usersList = usersList;
}
#NonNull
#Override
public UserHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View userLayout= LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_list,parent,false);
return new UserHolder(userLayout);
}
#Override
public void onBindViewHolder(#NonNull UserHolder holder, int position) {
Users users=usersList.get(position);
holder.Name_id.setText(users.getName());
holder.Type_id.setText(users.getType());
holder.Location_id.setText(users.getLocation());
holder.Time_id.setText(users.getTime());
holder.Date_id.setText(users.getDate());
holder.Slots_id.setText(users.getMaxparticipants());
holder.cardView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(context, cardviewclick.class);
intent.putExtra("Name",holder.Name_id.getText());
intent.putExtra("Type",holder.Type_id.getText());
intent.putExtra("Location",holder.Location_id.getText());
intent.putExtra("Time",holder.Time_id.getText());
intent.putExtra("Date",holder.Date_id.getText());
intent.putExtra("Slots",holder.Slots_id.getText());
context.startActivity(intent);
}
});
}
#Override
public int getItemCount() {
return usersList.size();
}
public class UserHolder extends RecyclerView.ViewHolder{
TextView Name_id,Type_id,Location_id,Time_id,Date_id,Slots_id;
CardView cardView;
public UserHolder(#NonNull View itemView){
super(itemView);
Name_id=itemView.findViewById(R.id.textTitle);
Type_id=itemView.findViewById(R.id.textType);
Location_id=itemView.findViewById(R.id.textLocation);
Time_id=itemView.findViewById(R.id.textTime);
Date_id=itemView.findViewById(R.id.textDate);
Slots_id=itemView.findViewById(R.id.textSlots);
cardView=itemView.findViewById(R.id.card);
}
}
}
activitydisplay.php
conn = new mysqli($servername, $username, $password, $dbname);
$stmt = $conn->prepare("SELECT eventname, type ,location,maxparticipants,time,date FROM activitytable");
$stmt ->execute();
$stmt -> bind_result($eventname, $type, $location,$maxparticipants,$time,$date);
$data= array();
while($stmt ->fetch()){
$temp = array();
$temp['eventname'] = $eventname;
$temp['type'] = $type;
$temp['location'] = $location;
$temp['maxparticipants'] = $maxparticipants;
$temp['time'] = $time;
$temp['date'] = $date;
array_push($data,$temp);
}
echo json_encode($data);
?>
edit 1:add xml code
main activity 2
<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"
tools:context=".MainActivity2">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recylcerList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
card xml
<?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="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:id="#+id/card"
app:cardElevation="12dp"
app:cardCornerRadius="16dp"
android:layout_margin="16dp"
android:backgroundTint="#efefef"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal" >
<TextView
style="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title:"
android:textColor="#color/black"
android:textSize="24dp" />
<TextView
android:id="#+id/textTitle"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="24dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal" >
<TextView
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Type:"
android:textColor="#color/black"
android:textSize="24dp" />
<TextView
android:id="#+id/textType"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="24dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal" >
<TextView
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Location:"
android:textColor="#color/black"
android:textSize="24dp" />
<TextView
android:id="#+id/textLocation"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="24dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal" >
<TextView
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date:"
android:textColor="#color/black"
android:textSize="24dp" />
<TextView
android:id="#+id/textDate"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="24dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal" >
<TextView
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time:"
android:textColor="#color/black"
android:textSize="24dp" />
<TextView
android:id="#+id/textTime"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="24dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal" >
<TextView
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Slots:"
android:textColor="#color/black"
android:textSize="24dp" />
<TextView
android:id="#+id/textSlots"
style="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="24dp" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
It is because the LinearLayout of the card has match_parent as its layout_height and layout_width so it is taking up the whole space. Can you try to scroll the card up?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent" <-------- here
android:layout_height="match_parent">. <-------- here
The layout_height should be wrap_content.
I wrote a little code, but I had a problem. Error that I encounter as: android.widget.RelativeLayout cannot be cast to androidx.recyclerview.widget.RecyclerView
I looked at the questions that look like this, but the answers that were given did not solve my problem. Can you help me?
Java code as:
public class Fehrest extends AppCompatActivity {
DatabaseManager dbManager = new DatabaseManager();
int tedad,tedad_fav;
private String[] Name, Text,Image,seen, English, Farsi;
private int[] id,fav,id_sen;
Items items = new Items();
SharedPreferences sharedP;
RecyclerView recyclerView;
Story_Adapter adapter;
ArrayList<Book_Items> MyArrayList = new ArrayList<>();
String button_name,tbl_name="story_tbl";
TextView txt_toolbar,txt_sen;
BrokenView brokenView;
BrokenTouchListener listener;
EditText edt_search;
LinearLayout lin_main;
RelativeLayout rlt_buttons;
boolean night_mode,show_english=true;
int day=0,date_mod,today;
Button btn_love,btn_pand,btn_tanz,btn_mazhabi;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.movies_list);
recyclerView = findViewById(R.id.rcl_movies);
edt_search = findViewById(R.id.edt_search);
rlt_buttons = findViewById(R.id.rlt_buttons);
txt_toolbar = findViewById(R.id.txt_toolbar);
lin_main = findViewById(R.id.lin_main);
txt_sen = findViewById(R.id.txt_sen);
btn_love = findViewById(R.id.btn_love);
btn_pand = findViewById(R.id.btn_pand);
btn_mazhabi = findViewById(R.id.btn_mazhabi);
btn_tanz = findViewById(R.id.btn_tanz);
brokenView = BrokenView.add2Window(Fehrest.this);
listener = new BrokenTouchListener.Builder(brokenView).build();
sharedP = getSharedPreferences(Items.SETTINGS, Context.MODE_PRIVATE);
night_mode = sharedP.getBoolean(Items.NIGHT_MODE,false);
today = sharedP.getInt(Items.TODAY,0);
date_mod = sharedP.getInt(Items.DATE_MODIFIED,0);
day = (today - date_mod);
get_night();
Get_sentence();
adapter = new Story_Adapter(this, MyArrayList);
recyclerView.setLayoutManager(new LinearLayoutManager(Fehrest.this,LinearLayoutManager.VERTICAL,false));
recyclerView.setAdapter(adapter);
button_name = getIntent().getStringExtra("button");
and this my xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Fehrest"
android:orientation="vertical"
android:id="#+id/lin_main"
android:background="#drawable/background4">
<LinearLayout
android:id="#+id/lin_toolbar"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginBottom="8dp"
android:background="#color/nephritis"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="7"
>
<EditText
android:id="#+id/edt_search"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="6"
android:background="#drawable/textviewstyle2"
android:gravity="center"
android:hint="جستجو..."
android:padding="4dp"
android:textColorHint="#color/White"
android:textColor="#color/White"
android:visibility="gone"/>
<TextView
android:id="#+id/txt_toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="6"
android:text="لیست خانوائخ خاا"
android:textColor="#color/White"
android:textSize="21sp"
android:fontFamily="#font/medium"/>
<ImageView
android:id="#+id/img_search"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_weight="1"
android:src="#drawable/magnify"
android:onClick="img_search_click"/>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rcl_movies"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:visibility="gone"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/rlt_buttons">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
android:orientation="horizontal">
<TextView
android:id="#+id/txt_sen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_marginStart="20dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="20dp"
android:background="#drawable/textviewstyle"
android:fontFamily="#font/zahraroosta"
android:padding="8dp"
android:text="Sentence"
android:textColor="#color/description"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="#+id/btn_love"
android:layout_width="290dp"
android:layout_height="70dp"
android:layout_below="#id/txt_sen"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_gravity="center"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:background="#drawable/back_btn3"
android:fontFamily="#font/boldmayriad"
android:onClick="btn_click"
android:paddingEnd="40dp"
android:text="#string/euphorbiaceae"
android:textAllCaps="false"
android:textColor="#color/White"
android:textSize="24sp" />
This is part of my MLX code and the tags are not closed for this reason.
I have 2 views for an item ListView. So one is used as HeaderView for ListView and the other in the other. That is the second marking takes the data from the DetailsAdapter, which respectively are initialized fields.
public class DetailsAdapter extends ArrayAdapter<TicketObjects> {
private int resource;
private LayoutInflater inflater;
private Context context;
public DetailsAdapter ( Context ctx, int resourceId, List<TicketObjects> objects) {
super( ctx, resourceId, objects );
resource = resourceId;
inflater = LayoutInflater.from( ctx );
context=ctx;
}
#Override
public View getView ( int position, View convertView, ViewGroup parent ) {
convertView = (LinearLayout) inflater.inflate( resource, null );
TicketObjects ticketObjects = getItem( position );
TextView depTransferCity = (TextView) convertView.findViewById(R.id.tvTransferCity);
TextView detDepartTime = (TextView) convertView.findViewById(R.id.detDepartTime);
TextView detDepartDate = (TextView) convertView.findViewById(R.id.detDepartDate);
TextView detArriveTime = (TextView) convertView.findViewById(R.id.detArriveTime);
TextView detArriveDate = (TextView) convertView.findViewById(R.id.detArriveDate);
TextView depDepartCity = (TextView) convertView.findViewById(R.id.depDepartCity);
TextView detDepartAirport = (TextView) convertView.findViewById(R.id.detDepartAirport);
TextView detArriveCity = (TextView) convertView.findViewById(R.id.detArriveCity);
TextView detArriveAirport = (TextView) convertView.findViewById(R.id.detArriveAirport);
TextView detFlight = (TextView) convertView.findViewById(R.id.detFlight);
ImageView airlineLogo = (ImageView) convertView.findViewById(R.id.detAirportLogo);
depTransferCity.setText(ticketObjects.getTransferCity());
detDepartTime.setText(ticketObjects.getDepartTime());
detDepartDate.setText(ticketObjects.getDepartDate());
detArriveTime.setText(ticketObjects.getArriveTime());
detArriveDate.setText(ticketObjects.getArriveDate());
depDepartCity.setText(ticketObjects.getDepartCity());
detDepartAirport.setText(ticketObjects.getDepartAirport());
detArriveCity.setText(ticketObjects.getArriveCity());
detArriveAirport.setText(ticketObjects.getArriveAirport());
detFlight.setText(ticketObjects.getFlight());
airlineLogo.setImageResource(ticketObjects.getAirlineLogo());
return convertView;
}
}
MainActivity:
public class MainActivity extends Activity {
private ListView lvDetails;
private Context ctx;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ticket_details);
ctx=this;
List<TicketObjects> ticketObjectses = new ArrayList<>();
ticketObjectses.add(new TicketObjects("Бишкек", "Манас", "Ош", "Аэропорт Оша", "FRU", "13:45", "16.09.2015", "OSS", "13:45", "16.09.2015", "Almaty", "1ч 15мин", "15000", R.drawable.logo_flyduba, "Рейс: 543"));
ticketObjectses.add(new TicketObjects("Ош", "Аэропорт Оша", "Новосибирск", "Толмачево", "OSS", "15:43", "16.09.2015", "OVB", "17:45", "16.09.2015", "Astana", "1ч 25мин", "16000", R.drawable.logo_kazak, "Рейс: 543"));
ticketObjectses.add(new TicketObjects("Алматы", "Алматы", "Москва", "Домодедово","ALA","11:54","16.09.2015","DME","12:44","16.09.2015","Novosibirsk", "2ч 15мин","13000", R.drawable.logo_pegasus_logo, "Рейс: 543"));
lvDetails = ( ListView ) findViewById( R.id.lvDetails);
ViewGroup header = (ViewGroup) getLayoutInflater().inflate(R.layout.ticket_details_header_item,lvDetails,false);
lvDetails.addHeaderView(header);
lvDetails.setAdapter(new DetailsAdapter(ctx, R.layout.ticket_details_item, ticketObjectses));
}
}
ticket_details_item_header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/leftPadding"
android:layout_below="#+id/line"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/linearLayout"
android:background="#drawable/layouts_border">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/iconsSize"
android:layout_gravity="center_horizontal"
android:padding="#dimen/leftPadding"
android:background="#e8e8e8"
android:layout_marginBottom="#dimen/rightPadding">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Бишкек"
android:id="#+id/detTitleArriveCity"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize"
android:textStyle="bold"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/imageView"
android:layout_toStartOf="#+id/imageView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Нью-Йорк"
android:id="#+id/detTitleArriveCity"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize"
android:textStyle="bold"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/imageView"
android:layout_toEndOf="#+id/imageView" />
<ImageView
android:layout_width="#dimen/smallIconSize"
android:layout_height="#dimen/smallIconSize"
android:id="#+id/imageView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/icon_depart"
android:padding="#dimen/rightPadding"
android:layout_marginLeft="#dimen/rightPadding"
android:layout_marginRight="#dimen/rightPadding" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="35ч 00м"
android:id="#+id/detTotalDuration"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainSmallSize"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/leftPadding"
android:gravity="center_vertical"
android:paddingLeft="#dimen/text_margin">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/rightPadding"
android:layout_weight="3"
android:gravity="center">
<ImageView
android:layout_width="#dimen/smallIconSize"
android:layout_height="#dimen/smallIconSize"
android:id="#+id/imageView2"
android:src="#drawable/from"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="#dimen/smallIconSize"
android:layout_height="#dimen/smallIconSize"
android:id="#+id/imageView3"
android:src="#drawable/punktir"
android:layout_below="#+id/imageView2"
android:layout_marginTop="-5dp" />
<ImageView
android:layout_width="#dimen/smallIconSize"
android:layout_height="#dimen/smallIconSize"
android:id="#+id/imageView4"
android:src="#drawable/to"
android:layout_below="#+id/imageView3"
android:layout_centerHorizontal="true"
android:layout_marginTop="-5dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/rightPadding"
android:layout_weight="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="09:50"
android:id="#+id/detDepartTime"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="12.06.2016"
android:id="#+id/detDepartDate"
android:layout_below="#+id/detDepartTime"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="#dimen/rightPadding"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainMiddleSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="11:40"
android:id="#+id/detArriveTime"
android:layout_below="#+id/detDepartDate"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="13.06.2016"
android:id="#+id/detArriveDate"
android:layout_below="#+id/detArriveTime"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainMiddleSize" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="#dimen/rightPadding"
android:layout_weight="2"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Бишкек"
android:id="#+id/depDepartCity"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Манас"
android:id="#+id/detDepartAirport"
android:layout_below="#+id/depDepartCity"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="#dimen/rightPadding"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainMiddleSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Москва"
android:id="#+id/detArriveCity"
android:layout_below="#+id/detDepartAirport"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Шереметьево"
android:id="#+id/detArriveAirport"
android:layout_below="#+id/detArriveCity"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainMiddleSize" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="#dimen/stndHeight"
android:layout_gravity="center_horizontal"
android:paddingTop="#dimen/leftPadding">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Рейс: AN565"
android:id="#+id/detFlight"
android:layout_weight="1"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/detAirportLogo"
android:src="#drawable/logo_flyduba"
android:layout_weight="1"
android:layout_gravity="center"
android:gravity="center_horizontal"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
ticket_details_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/leftPadding"
android:background="#e8e8e8"
android:gravity="center_vertical">
<ImageView
android:layout_width="#dimen/smallIconSize"
android:layout_height="#dimen/smallIconSize"
android:id="#+id/locIcon"
android:src="#drawable/location"
android:layout_weight="1"
android:padding="#dimen/leftPadding" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Пересадка:"
android:id="#+id/textviewTransfer"
android:layout_weight="3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvTransferCity"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize"
android:layout_weight="3" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/leftPadding"
android:gravity="center_vertical"
android:paddingLeft="#dimen/text_margin"
android:id="#+id/centerlayout">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/rightPadding"
android:layout_weight="3"
android:gravity="center">
<ImageView
android:layout_width="#dimen/smallIconSize"
android:layout_height="#dimen/smallIconSize"
android:id="#+id/imageView2"
android:src="#drawable/from"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="#dimen/smallIconSize"
android:layout_height="#dimen/smallIconSize"
android:id="#+id/imageView3"
android:src="#drawable/punktir"
android:layout_below="#+id/imageView2"
android:layout_marginTop="-5dp" />
<ImageView
android:layout_width="#dimen/smallIconSize"
android:layout_height="#dimen/smallIconSize"
android:id="#+id/imageView4"
android:src="#drawable/to"
android:layout_below="#+id/imageView3"
android:layout_centerHorizontal="true"
android:layout_marginTop="-5dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/rightPadding"
android:layout_weight="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="09:50"
android:id="#+id/detDepartTime"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="12.06.2016"
android:id="#+id/detDepartDate"
android:layout_below="#+id/detDepartTime"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="#dimen/rightPadding"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainMiddleSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="11:40"
android:id="#+id/detArriveTime"
android:layout_below="#+id/detDepartDate"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="13.06.2016"
android:id="#+id/detArriveDate"
android:layout_below="#+id/detArriveTime"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainMiddleSize" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="#dimen/rightPadding"
android:layout_weight="2"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Бишкек"
android:id="#+id/depDepartCity"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Манас"
android:id="#+id/detDepartAirport"
android:layout_below="#+id/depDepartCity"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="#dimen/rightPadding"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainMiddleSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Москва"
android:id="#+id/detArriveCity"
android:layout_below="#+id/detDepartAirport"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Шереметьево"
android:id="#+id/detArriveAirport"
android:layout_below="#+id/detArriveCity"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#color/mainGreyColor"
android:textSize="#dimen/mainMiddleSize" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="#dimen/stndHeight"
android:layout_gravity="center_horizontal"
android:paddingTop="#dimen/leftPadding">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Рейс: AN565"
android:id="#+id/detFlight"
android:layout_weight="1"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:textColor="#color/otherTextColor"
android:textSize="#dimen/mainLargeSize" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/detAirportLogo"
android:src="#drawable/logo_flyduba"
android:layout_weight="1"
android:layout_gravity="center"
android:gravity="center_horizontal"/>
</LinearLayout>
</LinearLayout>
Now ticket_details_header_item.xml nothing displays, that is, there are no data. A second view As you can see in the adapter is initialized and it has data.
DetailObjects
package kz.ticketdetail;
import java.text.DecimalFormat;
public class TicketObjects {
private String departCity;
private String departAirport;
private String arriveCity;
private String arriveAirport;
private String departCode;
private String departTime;
private String departDate;
private String arriveCode;
private String arriveTime;
private String arriveDate;
private String transferCity;
private String flyDuration;
private String ticketPrice;
private int airlineLogo;
private String flight;
public TicketObjects(String departCity, String departAirport, String arriveCity, String arriveAirport,
String departCode, String departTime, String departDate,
String arriveCode, String arriveTime, String arriveDate,
String transferCity, String flyDuration, String ticketPrice, int airlineLogo, String flight) {
this.departCity = departCity;
this.departAirport = departAirport;
this.arriveCity = arriveCity;
this.arriveAirport = arriveAirport;
this.departCode = departCode;
this.departTime = departTime;
this.departDate = departDate;
this.arriveCode = arriveCode;
this.arriveTime = arriveTime;
this.arriveDate = arriveDate;
this.transferCity = transferCity;
this.flyDuration = flyDuration.trim().replaceFirst("^[0]{1}", "").replace(":", " h ") + " m";
this.ticketPrice = ticketPrice;
this.airlineLogo = airlineLogo;
this.flight = flight;
}
public static String getFormattingPrice(final String ticketPrice) throws IllegalArgumentException {
DecimalFormat formatter = new DecimalFormat("#,###,###");
return formatter.format(Float.parseFloat(ticketPrice)).replace(",", " ");
}
public String getDepartCity(){
return departCity;
}
public void setDepartCity(String departCity){
this.departCity = departCity;
}
public String getDepartAirport(){
return departAirport;
}
public void setDepartAirport(String departAirport){
this.departAirport = departAirport;
}
public String getArriveCity(){
return arriveCity;
}
public void setArriveCity(String arriveCity){
this.arriveCity = arriveCity;
}
public String getArriveAirport(){
return arriveAirport;
}
public void setArriveAirport(String arriveAirport){
this.arriveAirport = arriveAirport;
}
public String getFlight(){
return flight;
}
public void setFlight(String flight){
this.flight = flight;
}
public String getDepartCode(){
return departCode;
}
public void setDepartCode(String departCode){
this.departCode = departCode;
}
public String getDepartTime(){
return departTime;
}
public void setDepartTime(String departTime){
this.departTime = departTime;
}
public String getDepartDate(){
return departDate;
}
public void setDepartDate(String departDate){
this.departDate = departDate;
}
public String getArriveCode(){
return arriveCode;
}
public void setArriveCode(String arriveCode){
this.arriveCode = arriveCode;
}
public String getArriveTime(){
return arriveTime;
}
public void setArriveTime(String arriveTime){
this.arriveTime = arriveTime;
}
public String getArriveDate(){
return arriveDate;
}
public void setArriveDate(String arriveDate){
this.arriveDate = arriveDate;
}
public String getTransferCity(){
return transferCity;
}
public void setTransferCity(String transferCity){
this.transferCity = transferCity;
}
public String getFlyDuration(){
return flyDuration;
}
public void setFlyDuration(String flyDuration){
this.flyDuration = flyDuration;
}
public String getTicketPrice(){
return ticketPrice;
}
public void setTicketPrice(String ticketPrice){
this.ticketPrice = ticketPrice;
}
public int getAirlineLogo(){
return airlineLogo;
}
public void setAirlineLogo(int airlineLogo){
this.airlineLogo = airlineLogo;
}
}
Question: How header view display the data from the array which MainActivity? Where should occur initialization ticket_details_header_item?
You need to get the view from header and set data like this.
public class MainActivity extends Activity {
private ListView lvDetails;
private Context ctx;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ticket_details);
ctx=this;
List<TicketObjects> ticketObjectses = new ArrayList<>();
ticketObjectses.add(new TicketObjects("Бишкек", "Манас", "Ош", "Аэропорт Оша", "FRU", "13:45", "16.09.2015", "OSS", "13:45", "16.09.2015", "Almaty", "1ч 15мин", "15000", R.drawable.logo_flyduba, "Рейс: 543"));
ticketObjectses.add(new TicketObjects("Ош", "Аэропорт Оша", "Новосибирск", "Толмачево", "OSS", "15:43", "16.09.2015", "OVB", "17:45", "16.09.2015", "Astana", "1ч 25мин", "16000", R.drawable.logo_kazak, "Рейс: 543"));
ticketObjectses.add(new TicketObjects("Алматы", "Алматы", "Москва", "Домодедово","ALA","11:54","16.09.2015","DME","12:44","16.09.2015","Novosibirsk", "2ч 15мин","13000", R.drawable.logo_pegasus_logo, "Рейс: 543"));
lvDetails = ( ListView ) findViewById( R.id.lvDetails);
View header = getLayoutInflater().inflate(R.layout.ticket_details_header_item,lvDetails,false);
TextView text1 = (TextView) header.findViewById(R.id.detTitleArriveCity);
TextView text2 = (TextView) header.findViewById(R.id.detTotalDuration);
// do the same far all your text views or what ever you want to get from layout.
TicketObjects mTicketObjects = ticketObjectses.get(0);
text1.setText(mTicketObjects.getDepartCity());
text2.setText(mTicketObjects.getFlyDuration());
// do the same for other options.
lvDetails.addHeaderView(header);
lvDetails.setAdapter(new DetailsAdapter(ctx, R.layout.ticket_details_item, ticketObjectses));
}
}
do this for all items. inside the activity not in adapter. hope that answers your question.
I have a very crazy bug. When I create a TextView array and initialize them in onCreate with my id from xml, nothing is changed. I create a simple function to change anything, but I get a nullpointer exception. I don't have any idea what I'm doing wrong with my code.
I will be very gratefull for any help.
XML:
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="10"
>
<LinearLayout
android:id="#+id/keys"
.....
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="#+id/keys"
android:weightSum="6" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:hint="A"
android:layout_weight="1"
android:id="#+id/data1" android:layout_alignTop="#+id/linearLayout"
android:layout_alignParentLeft="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:hint="A"
android:layout_weight="1"
android:id="#+id/data2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:hint="A"
android:layout_weight="1"
android:id="#+id/data3"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:hint="A"
android:layout_weight="1"
android:id="#+id/data4"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:hint="A"
android:layout_weight="1"
android:id="#+id/data5"/>
</LinearLayout>
</RelativeLayout>
CODE:
public class XXX extends Activity {
private String login;
....
private TextView[] dates;
public void change(String x) {
if(dates[0].getEditableText().toString().compareTo("") == 0)
dates[0].setText(x);
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ABC);
dates = new TextView[5];
dates[0]=(TextView)findViewById(R.id.data1);
dates[1]= (TextView) findViewById(R.id.data2);
dates[2]=(TextView)findViewById(R.id.data3);
dates[3]=(TextView)findViewById(R.id.data4);
dates[4]=(TextView)findViewById(R.id.data5);
dates[0].setText("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
for (int i= 0; i < 5; i++){
dates[i].setText("LOL");
};
change("ROTFL");
}
i have try to retrieve data from mysql database via soap calling.
Here am facing following problem.
i have used below webservice code:
public class RetailerWs {
public String customerData1(){
String customerInfo = "";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xcart-432pro","root","");
//Find customer information where the customer ID is maximum
PreparedStatement statement = con.prepareStatement("SELECT * FROM xcart_orders");
ResultSet result = statement.executeQuery();
while(result.next()){
customerInfo = customerInfo
+ result.getString("orderid")
+ " " // this to separate order id from status
+ result.getString("status")
+ " "
+ result.getString("payment_method")
+ " "
+ result.getString("total")
+ " "
// this to separate order id from status
+ result.getString("login")
+ "&" ;
}}
catch(Exception exc){
System.out.println(exc.getMessage());
}
return customerInfo;
}}
This is my android code:
public class RetailerActivity extends Activity {
ListView list;
private static final String SOAP_ACTION = "http://xcart.com/customerData1";
private static final String METHOD_NAME = "customerData1";
private static final String NAMESPACE = "http://xcart.com";
private static final String URL = "http://192.168.1.168:8089/XcartLogin/services/RetailerWs?wsdl";
private static final String KEY_STATUS = "status";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
try {
ht.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
SoapPrimitive s = response;
String str = s.toString();
String resultArr[] = str.split("&");
list=(ListView)findViewById(R.id.list);
// ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
//R.layout.list_row, R.id.orderid);
list.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1,resultArr));
list.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String s2= getIntent().getStringExtra("status");
// Starting new intent
Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
in.putExtra(KEY_STATUS, s2);
startActivity(in);
}
});
}
catch (Exception e) {
e.printStackTrace();
}
}
}
This is my current o/p:
But i wish to need the o/p like below format:
1 P 399.99
Krishna
Check(manual processing)
------------------------------
2 P 314.65
Krishna
Phone Ordering
------------------------------
please help me ..how can i develop this.
You can Do this by creating 2 xml
First xml would be defining your hearder of List View and your Data to be filled in List
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="#EFEFF7"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:paddingLeft="2px"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:text="ID" android:width="120dip" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:textSize="20sp" android:textColor="#000000"
android:height="25sp" />
<TextView android:text="Name" android:layout_weight="1.0" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:textSize="20sp" android:textColor="#000000"
android:height="25sp" />
<TextView android:text="Money ($)" android:width="80dip" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:textSize="20sp" android:textColor="#000000"
android:height="25sp" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="#000000" android:height="1sp">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:height="1sp" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:paddingLeft="2px"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#000000">
<ListView android:id="#+id/android:list" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1.0" />
</LinearLayout>
</LinearLayout>
and ListView which is First xml can be define in other other xml which item you need in ListView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/lv"
android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#000000">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#000000">
<TextView android:id="#+id/ID" android:textColor="#FFFFFF" android:typeface="sans"
android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content"
android:width="120dip" /> //Can use this ID to display ID for Example 1
<TextView android:id="#+id/Name" android:textColor="#FFFFFF" android:typeface="sans"
android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content"
android:layout_weight="1.0" /> //Can use this ID to display Name Like P
<TextView android:id="#+id/Money" android:textColor="#FFFFFF" android:typeface="sans"
android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content"
android:width="80dip" /> //Can use this ID to display Money like 300 $
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#EFEFF7">
<TextView android:textSize="20sp" android:text="Namee of person " android:textColor="#000000" android:typeface="sans"
android:layout_height="fill_parent" android:layout_width="wrap_content"
android:width="90dip" /> // you display krishna through this ID
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#EFEFF7">
<TextView android:textSize="20sp" android:text="Namee of person " android:textColor="#000000" android:typeface="sans"
android:layout_height="fill_parent" android:layout_width="wrap_content"
android:width="90dip" /> // you display phone ordering through this ID
</LinearLayout>
</LinearLayout>