I have made an application in android,now i have made activities notes.xml,contactinfo.xml and an android xml file named listplaceholder5.xml,i need is i've changed the android:text of textview to "notes"in "listplaceholder5.xml" file which is used in note.java but it ,not displaying "notes" its displaying "contact".i have tried sode a sbelow:please help me to change the code so that i can solve it,
Note.xml
<?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="fill_parent"
android:orientation="vertical"
>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name: "
android:textColor="#000000"
android:textStyle="bold"
android:textSize="16sp"
android:paddingLeft="5dp"
/>
<TextView
android:id="#+id/item_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="item_title"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="16sp"
android:paddingLeft="5dp"
android:ellipsize="end"
android:lines="1"
android:scrollHorizontally="true"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<!--
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="#string/hello"
android:visibility="gone"
/>-->
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone : "
android:textColor="#000000"
android:textSize="14sp"
android:paddingLeft="5dp"
/>
<TextView
android:id="#+id/item_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="item_subtitle"
android:textColor="#000000"
android:textSize="14sp"
/>
<TextView
android:id="#+id/item_subtitle1"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="14sp"
android:layout_width="wrap_content"
android:ellipsize="end"
android:lines="1"
android:scrollHorizontally="true"
/>
<!-- New Layout -->
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:paddingRight="10dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/forward" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
listplaceholder5.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/detailpage">
<LinearLayout android:layout_width="fill_parent"
android:weightSum="1"
android:background="#drawable/bottombackground"
android:id="#+id/linearLayout1"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:textColor="#FFFFFF"
android:layout_marginLeft="18dp"
android:layout_weight="0.88"
android:textSize="18sp"
android:textStyle="bold"
android:id="#+id/textView1"
android:text="Notes"
android:gravity="center"
android:layout_gravity="center"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
<ListView
android:id="#id/android:list"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:layout_width="fill_parent"
android:cacheColorHint="#00000000"
android:dividerHeight="2dp"
android:listSelector="#drawable/list_selector"
/>
<TextView
android:id="#id/android:empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="No data"/>
</LinearLayout>
NOteActivity.java
package com.hussain.realtylog;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.hussain.realtylog.Contact.DownloadWebPageTask;
import android.net.ConnectivityManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.GradientDrawable.Orientation;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;
public class NoteActivity extends ListActivity {
JSONArray jArray = null;
JSONObject json_data = null;
String getMLSID =null;
TextView titl;
// Button btnBuyer;
// Button btnRental;
String getJson =null;
public String user=null;
public static String urlContact=null;
public static String jsonContact=null;
ArrayList<HashMap<String, String>> mylist;
private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
private ProgressDialog dialog;
#Override
protected String doInBackground(String... urls) {
user= TabBarExample.getJsonUser;
urlContact = StoreSession.strBaseURL+"&username="+user+"&act=ContactList";
if( StoreSession.FlagContact == 0){
boolean isNet = checkInternetConnection();
if(isNet==true){
jsonContact = JSONfunctions.getJSONfromURL(urlContact);
}else{
alertbox("Contact", "Please check your mobile network setting and try again.");
}
}
mylist = new ArrayList<HashMap<String, String>>();
try{
jArray = new JSONArray(jsonContact);
for(int i=0;i<jArray.length();i++){
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = jArray.getJSONObject(i);
map.put("id", String.valueOf(i));
map.put("ID", e.getString("ID"));
map.put("username", e.getString("username"));
map.put("email", e.getString("email"));
map.put("phone", e.getString("phone"));
map.put("phone2", e.getString("phone2"));
map.put("fullname", e.getString("fullname"));
map.put("address", e.getString("address"));
map.put("notes", e.getString("info"));
map.put("active", e.getString("active"));
map.put("created", e.getString("created"));
map.put("lastUpdate", e.getString("lastUpdate"));
map.put("guest", e.getString("guest"));
map.put("category", "Category: "+e.getString("category"));
mylist.add(map);
}
}catch(JSONException e){
// Log.e("log_tag", "Error parsing data "+e.toString());
}
return null;
}
#Override
protected void onPostExecute(String result) {
ListAdapter adapter = new SimpleAdapter(NoteActivity.this, mylist , R.layout.activity_note,
new String[] { "fullname", "phone" },
new int[] { R.id.item_title, R.id.item_subtitle });
setListAdapter(adapter);
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
int[] colors = {0, 0xFFFF0000, 0}; // red for the example
lv.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
lv.setDividerHeight(1);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
final ProgressDialog dialog = ProgressDialog.show(NoteActivity.this, "Loading",
"Please wait...", true);
final Handler handler = new Handler() {
public void handleMessage(Message msg) {
dialog.dismiss();
}
};
Thread checkUpdate = new Thread() {
#SuppressWarnings("unchecked")
public void run() {
HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
final String strName= o.get("fullname").toString();
final String strEmail= o.get("email").toString();
final String Phone= o.get("phone").toString();
final String Phone2= o.get("phone2").toString();
getMLSID = o.get("notes").toString();
Intent newActivityFirst = new Intent(NoteActivity.this, ContactInfo.class);
newActivityFirst.putExtra("name", strName);
newActivityFirst.putExtra("strEmail", strEmail);
newActivityFirst.putExtra("phone", Phone);
newActivityFirst.putExtra("phone2", Phone2);
newActivityFirst.putExtra("notes", getMLSID);
NoteActivity.this.startActivity(newActivityFirst);
handler.sendEmptyMessage(0);
}
};
checkUpdate.start();
}
});
StoreSession.FlagContact=1;
//dialog.hide();
dialog.dismiss();
}
private ListView getListView() {
// TODO Auto-generated method stub
return null;
}
private void setListAdapter(ListAdapter adapter) {
// TODO Auto-generated method stub
}
protected void onPreExecute() {
dialog = new ProgressDialog(NoteActivity.this);
dialog.setCancelable(true);
dialog.setMessage("Please wait...");
dialog.show();
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_note);
DownloadWebPageTask task = new DownloadWebPageTask();
task.execute();
setContentView(R.layout.listplaceholder5);
TextView title=(TextView)findViewById(R.id.textView1);
title.setText("Notes");
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
StoreSession.FlagListing =0;
StoreSession.FlagBuyer =0;
StoreSession.FlagRental =0;
StoreSession.FlagDocument =0;
StoreSession.FlagContact =0;
ActiveShowingInfo.flagActiveClickCheck =0;
Main.username.setText("");
Main.pwd.setText("");
return false;
}
return super.onKeyDown(keyCode, event);
}
protected void alertbox(String title, String mymessage)
{
new AlertDialog.Builder(this)
.setMessage(mymessage)
.setTitle(title)
.setCancelable(true)
.setNeutralButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){}
})
.show();
}
private boolean checkInternetConnection() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
// test for connection
if (cm.getActiveNetworkInfo() != null
&& cm.getActiveNetworkInfo().isAvailable()
&& cm.getActiveNetworkInfo().isConnected()) {
return true;
} else {
//Log.v("tag", "Internet Connection Not Present");
return false;
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_note, menu);
return true;
}
}
please help me to solve this problem.thanking you in advance.
after getting the title as follows:
title= (TextView) findViewById(R.id.item_title);
use setText method to set the title as you wish.
I think it will solve your problem.
Related
I have method loadFragment(); In which i load the DashboardFragment which is having a framelayout widget. But inside the loadFragment() i get a null pointer exception and i dont know why. I have attached the loadFragment(). please help me. Thanks!
The error is:
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.widget.FrameLayout.getId()' on a null object reference.
at com.qdocs.smartschool.fragments.StudentDashboardFragment.loadFragment(StudentDashboardFragment.java:241)
loadFragment(new DashboardCalender());
private void loadFragment(Fragment fragment) {
// load fragment
FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
transaction.replace(calenderFrame.getId(), fragment);
transaction.addToBackStack(null);
transaction.commit();
}
The studentDashboardFragment class
package com.qdocs.smartschool.fragments;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.CardView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.qdocs.smartschool.R;
import com.qdocs.smartschool.students.StudentAttendance;
import com.qdocs.smartschool.students.StudentHomework;
import com.qdocs.smartschool.students.StudentTasks;
import com.qdocs.smartschool.utils.Constants;
import com.qdocs.smartschool.utils.Utility;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
public class StudentDashboardFragment extends Fragment {
RelativeLayout attendanceLayout, homeworkLayout, pendingTaskLayout;
TextView attendanceValue, homeworkValue, pendingTaskValue;
CardView attendanceCard, homeworkCard, pendingTaskCard;
FrameLayout calenderFrame;
public Map<String, String> headers = new HashMap<String, String>();
public Map<String, String> params = new Hashtable<String, String>();
public StudentDashboardFragment() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
loadData();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View mainView = inflater.inflate(R.layout.student_dashboard_fragment, container, false);
attendanceLayout = mainView.findViewById(R.id.student_dashboard_fragment_attendanceView);
homeworkLayout = mainView.findViewById(R.id.student_dashboard_fragment_homeworkView);
pendingTaskLayout = mainView.findViewById(R.id.student_dashboard_fragment_pendingTaskView);
attendanceCard = mainView.findViewById(R.id.student_dashboard_fragment_attendanceCard);
homeworkCard = mainView.findViewById(R.id.student_dashboard_fragment_homeworkCard);
pendingTaskCard = mainView.findViewById(R.id.student_dashboard_fragment_pendingTaskCard);
attendanceValue = mainView.findViewById(R.id.student_dashboard_fragment_attendance_value);
homeworkValue = mainView.findViewById(R.id.student_dashboard_fragment_homework_value);
pendingTaskValue = mainView.findViewById(R.id.student_dashboard_fragment_pendingTask_value);
calenderFrame = mainView.findViewById(R.id.dashboardViewPager);
loadData();
attendanceLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent asd = new Intent(getActivity().getApplicationContext(), StudentAttendance.class);
getActivity().startActivity(asd);
}
});
homeworkLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent asd = new Intent(getActivity().getApplicationContext(), StudentHomework.class);
getActivity().startActivity(asd);
}
});
pendingTaskLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent asd = new Intent(getActivity().getApplicationContext(), StudentTasks.class);
getActivity().startActivity(asd);
}
});
Log.e("STATUS", "onCreateView");
return mainView;
}
private void loadData() {
//decorate();
loadFragment(new DashboardCalender());
params.put("student_id", Utility.getSharedPreferences(getActivity().getApplicationContext(), Constants.studentId));
params.put("date_from", getDateOfMonth(new Date(), "first"));
params.put("date_to", getDateOfMonth(new Date(), "last"));
JSONObject obj=new JSONObject(params);
Log.e("params ", obj.toString());
getDataFromApi(obj.toString());
try {
JSONArray modulesArray = new JSONArray(Utility.getSharedPreferences(getActivity().getApplicationContext(), Constants.modulesArray));
if(modulesArray.length() != 0) {
ArrayList<String> moduleCodeList = new ArrayList<String>();
ArrayList<String> moduleStatusList = new ArrayList<String>();
for (int i = 0; i<modulesArray.length(); i++) {
if(modulesArray.getJSONObject(i).getString("short_code").equals("student_attendance")
&& modulesArray.getJSONObject(i).getString("is_active").equals("0") ) {
attendanceCard.setVisibility(View.GONE);
} if(modulesArray.getJSONObject(i).getString("short_code").equals("homework")
&& modulesArray.getJSONObject(i).getString("is_active").equals("0") ) {
homeworkCard.setVisibility(View.GONE);
} if(modulesArray.getJSONObject(i).getString("short_code").equals("calendar_to_do_list")
&& modulesArray.getJSONObject(i).getString("is_active").equals("0") ) {
pendingTaskCard.setVisibility(View.GONE);
calenderFrame.setVisibility(View.GONE);
}
}
}
} catch (JSONException e) {
Log.d("Error", e.toString());
}
}
private void getDataFromApi (String bodyParams) {
Log.e("RESULT PARAMS", bodyParams);
final ProgressDialog pd = new ProgressDialog(getActivity());
pd.setMessage("Loading");
pd.setCancelable(false);
pd.show();
final String requestBody = bodyParams;
String url = Utility.getSharedPreferences(getActivity().getApplicationContext(), "apiUrl") + Constants.getDashboardUrl;
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
#Override
public void onResponse(String result) {
if (result != null) {
pd.dismiss();
try {
Log.e("Result", result);
JSONObject object = new JSONObject(result);
//TODO success
String success = "1"; //object.getString("success");
if (success.equals("1")) {
if(object.getString("attendence_type").equals("0")){
attendanceValue.setText(object.getString("student_attendence_percentage") + "%");
}else{
attendanceCard.setVisibility(View.GONE);
}
homeworkValue.setText(object.getString("student_homework_incomplete"));
pendingTaskValue.setText(object.getString("student_incomplete_task"));
String classid = object.getString("class_id");
Utility.setSharedPreference(getActivity().getApplicationContext(), Constants.classId, classid);
Utility.setSharedPreference(getActivity().getApplicationContext(), Constants.sectionId, object.getString("section_id"));
} else {
Toast.makeText(getActivity().getApplicationContext(), object.getString("errorMsg"), Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
pd.dismiss();
Toast.makeText(getActivity().getApplicationContext(), R.string.noInternetMsg, Toast.LENGTH_SHORT).show();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError volleyError) {
pd.dismiss();
Log.e("Volley Error", volleyError.toString());
Toast.makeText(getActivity(), R.string.slowInternetMsg, Toast.LENGTH_LONG).show();
}
}) {
#Override
public Map<String, String> getHeaders() throws AuthFailureError {
headers.put("Client-Service", Constants.clientService);
headers.put("Auth-Key", Constants.authKey);
headers.put("Content-Type", Constants.contentType);
headers.put("User-ID", Utility.getSharedPreferences(getActivity().getApplicationContext(), "userId"));
headers.put("Authorization", Utility.getSharedPreferences(getActivity().getApplicationContext(), "accessToken"));
return headers;
}
#Override
public String getBodyContentType() {
return "application/json; charset=utf-8";
}
#Override
public byte[] getBody() throws AuthFailureError {
try {
return requestBody == null ? null : requestBody.getBytes("utf-8");
} catch (UnsupportedEncodingException uee) {
VolleyLog.wtf("Unsupported Encoding while trying to get the bytes of %s using %s", requestBody, "utf-8");
return null;
}
}
};
RequestQueue requestQueue = Volley.newRequestQueue(getActivity());//Creating a Request Queue
requestQueue.add(stringRequest);//Adding request to the queue
}
private void decorate() {
attendanceLayout.setBackgroundColor(Color.parseColor(Constants.defaultSecondaryColour));
homeworkLayout.setBackgroundColor(Color.parseColor(Constants.defaultSecondaryColour));
pendingTaskLayout.setBackgroundColor(Color.parseColor(Constants.defaultSecondaryColour));
}
private void loadFragment(Fragment fragment) {
// load fragment
FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
// transaction.replace(calenderFrame.getId(), fragment);
transaction.addToBackStack(null);
transaction.commit();
}
public static String getDateOfMonth(Date date, String index){
Calendar cal = Calendar.getInstance();
cal.setTime(date);
if(index.equals("first")) {
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
} else {
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
}
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
return dateFormatter.format(cal.getTime());
}
}
The xml containing viewpager
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/student_dashboard_fragment_attendanceCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/CustomCardView"
>
<RelativeLayout
android:id="#+id/student_dashboard_fragment_attendanceView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingStart="10dp"
>
<ImageView
android:id="#+id/student_dashboard_fragment_attendanceView_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentStart="true"
android:src="#drawable/ic_dashboard_attendance"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
/>
<RelativeLayout
android:id="#+id/student_dashboard_fragment_attendance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="35dp"
android:layout_marginEnd="60dp"
android:layout_marginTop="10dp"
>
<TextView
android:id="#+id/student_dashboard_fragment_attendance_head"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17sp"
android:gravity="start|center"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:textColor="#color/textHeading"
android:text="#string/attendance"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:gravity="start|center"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:text="#string/thisMonth"
android:textColor="#color/textHeading"
android:layout_below="#+id/student_dashboard_fragment_attendance_head"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="5dp"
>
<TextView
android:id="#+id/student_dashboard_fragment_attendance_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp"
android:gravity="center"
android:textColor="#color/textHeading"
/>
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/student_dashboard_fragment_homeworkCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/CustomCardView"
>
<RelativeLayout
android:id="#+id/student_dashboard_fragment_homeworkView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingStart="10dp"
>
<ImageView
android:id="#+id/student_dashboard_fragment_homeworkView_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentStart="true"
android:src="#drawable/ic_dashboard_homework"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
/>
<RelativeLayout
android:id="#+id/student_dashboard_fragment_homework"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="35dp"
android:layout_marginEnd="60dp"
android:layout_marginTop="10dp"
>
<TextView
android:id="#+id/student_dashboard_fragment_homework_head"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17sp"
android:gravity="start|center"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:textColor="#color/textHeading"
android:text="#string/homework"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:gravity="start|center"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:text="#string/incomplete"
android:textColor="#color/textHeading"
android:layout_below="#+id/student_dashboard_fragment_homework_head"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="5dp"
>
<TextView
android:id="#+id/student_dashboard_fragment_homework_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp"
android:gravity="center"
android:textColor="#color/textHeading"
/>
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/student_dashboard_fragment_pendingTaskCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/CustomCardView"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/student_dashboard_fragment_pendingTaskView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingStart="10dp"
>
<ImageView
android:id="#+id/student_dashboard_fragment_pendingTaskView_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentStart="true"
android:src="#drawable/ic_dashboard_pandingtask"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
/>
<RelativeLayout
android:id="#+id/student_dashboard_fragment_pendingTask"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="35dp"
android:layout_marginEnd="60dp"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/student_dashboard_fragment_pendingTask_head"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17sp"
android:gravity="start|center"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:textColor="#color/textHeading"
android:text="#string/pendingTask" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:gravity="start|center"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:text="#string/today"
android:textColor="#color/textHeading"
android:layout_below="#+id/student_dashboard_fragment_pendingTask_head" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="5dp">
<TextView
android:id="#+id/student_dashboard_fragment_pendingTask_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp"
android:gravity="center"
android:textColor="#color/textHeading"
/>
</RelativeLayout>
</RelativeLayout>
<FrameLayout
android:id="#+id/dashboardViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/textHeading"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
the error is quite self-explanatory. calenderFrame is null, meaning that you never initialized it.
I have found the answer. In onCreate() of fragment my code was calling the loadFragment() method before initializing the calenderFrame.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have a table in Mysql database with some plugs, and i added all the plugs to spinner from database.I want to retreive the data according to spinner selection.I am facing a problem that there is two records in database for plug1,when i selected plug1 its retreiving properly,when i selected plug2 in spinner its retreiving another record of plug1. I have used on-selected item position that is why it is taking position wise order.
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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".DashboardActivity"
android:orientation="vertical"
android:background=" #dfe3e7"
tools:showIn="#layout/app_bar_dashboard">
<Spinner
android:id="#+id/spinnerDevices"
android:layout_width="150dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="#drawable/spinner"
android:layout_marginTop="20dp"
android:overlapAnchor="false"></Spinner>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="serif"
android:text="ON/OFF"
android:textSize="20sp"
android:paddingLeft="5dp"/>
<Switch
android:id="#+id/on"
android:layout_width="100dp"
android:layout_height="45dp"
android:checkable="true"
android:padding="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="15dp"
>
<android.support.v7.widget.CardView
android:layout_width="130dp"
android:layout_height="180dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background=" #1c2833"
android:padding="8dp">
<ImageView
android:id="#+id/imageView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#drawable/image1"
android:layout_marginLeft="20dp"/>
<TextView
android:id="#+id/device1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageView1"
android:layout_marginTop="10dp"
android:layout_marginLeft="1dp"
android:fontFamily="serif"
android:text="TEMPERATURE"
android:textColor="#fff"
android:textSize="15sp" />
<TextView
android:id="#+id/meter1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/device1"
android:fontFamily="serif"
android:layout_marginTop="10dp"
android:layout_marginLeft="50dp"
android:textColor="#ff6861"
android:textSize="30sp"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="130dp"
android:layout_height="180dp"
android:layout_margin="1dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background=" #1c2833"
android:padding="7dp">
<ImageView
android:id="#+id/imageView2"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#drawable/image2"
android:layout_marginLeft="20dp"/>
<TextView
android:id="#+id/device2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageView2"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:fontFamily="serif"
android:textColor="#fff"
android:text="CURRENT"
android:textSize="15sp" />
<TextView
android:id="#+id/meter2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/device2"
android:fontFamily="serif"
android:layout_marginTop="10dp"
android:layout_marginLeft="50dp"
android:textColor="#ff6861"
android:textSize="30sp"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="130dp"
android:layout_height="180dp"
android:layout_margin="1dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background=" #1c2833"
android:padding="7dp">
<ImageView
android:id="#+id/imageView3"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#drawable/image3"
android:layout_marginLeft="20dp"/>
<TextView
android:id="#+id/device3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageView3"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:fontFamily="serif"
android:text="VOLTAGE"
android:textColor="#fff"
android:textSize="15sp" />
<TextView
android:id="#+id/meter3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/device3"
android:fontFamily="serif"
android:layout_marginTop="10dp"
android:layout_marginLeft="50dp"
android:textSize="30sp"
android:textColor="#ff6861"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>>
</LinearLayout
JAVA
package com.example.sp;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class DashboardActivity extends AppCompatActivity implements Spinner.OnItemSelectedListener , NavigationView.OnNavigationItemSelectedListener {
private static final String TAG = "DashboardActivity";
private String URLstring = "http://192.168.0.108/Smart/getdata.php";
public static final String JSON_ARRAY = "data";
public static final String EmployeeNamearray = "plugno";
private TextView textView;
String line=null;
private ArrayList<String> names = new ArrayList<String>();
private JSONArray data;
private JSONArray result;
private ArrayList<String> students;
private final int jsoncode = 1;
private Spinner spinner;
String status="";
private TextView textViewName, textViewCourse, textViewSession;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
textView = (TextView) findViewById(R.id.greeting_text_view);
spinner = (Spinner) findViewById(R.id.spinnerDevices);
names = new ArrayList<String>();
students = new ArrayList<String>();
getdata();
getData();
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
textViewName = (TextView) findViewById(R.id.meter1);
textViewCourse = (TextView) findViewById(R.id.meter2);
textViewSession = (TextView) findViewById(R.id.meter3);
spinner.setOnItemSelectedListener(this);
Switch s = (Switch) findViewById(R.id.on);
s.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
Toast.makeText(DashboardActivity.this, "switch is on", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(DashboardActivity.this, "switch is off", Toast.LENGTH_SHORT).show();
}
}
});
}
private void getData() {
//Creating a string request
StringRequest stringRequest = new StringRequest(Config.DATA_URL,
new Response.Listener<String>() {
#Override
public void onResponse(String response) {
JSONObject j = null;
try {
//Parsing the fetched Json String to JSON Object
j = new JSONObject(response);
//Storing the Array of JSON String to our JSON Array
result = j.getJSONArray(Config.JSON_ARRAY);
//Calling method getStudents to get the students from the JSON Array
getStudents(result);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
}
});
//Creating a request queue
RequestQueue requestQueue = Volley.newRequestQueue(this);
//Adding request to the queue
requestQueue.add(stringRequest);
}
private void getStudents(JSONArray j) {
//Traversing through all the items in the json array
for (int i = 0; i < j.length(); i++) {
try {
//Getting json object
JSONObject json = j.getJSONObject(i);
if(json.getString("plugno").equals("plugno")){
students.add(json.getString(Config.TAG_PLUGNO));
}
//Adding the name of the student to array list
} catch (JSONException e) {
e.printStackTrace();
}
}
//Setting adapter to show the items in the spinner
spinner.setAdapter(new ArrayAdapter<String>(DashboardActivity.this, android.R.layout.simple_spinner_dropdown_item, students));
spinner.setAdapter(new ArrayAdapter<String>(DashboardActivity.this, android.R.layout.simple_spinner_dropdown_item, names));
}
//Method to get student name of a particular position
private String getName(int position) {
String name = "";
try {
//Getting object of given index
JSONObject json = result.getJSONObject(position);
//Fetching name from that object
name = json.getString(Config.TAG_TEMPERATURE);
} catch (JSONException e) {
e.printStackTrace();
}
//Returning the name
return name;
}
//Doing the same with this method as we did with getName()
private String getCourse(int position) {
String course = "";
try {
JSONObject json = result.getJSONObject(position);
course = json.getString(Config.TAG_CURRENT);
} catch (JSONException e) {
e.printStackTrace();
}
return course;
}
//Doing the same with this method as we did with getName()
private String getSession(int position) {
String session = "";
try {
JSONObject json = result.getJSONObject(position);
session = json.getString(Config.TAG_VOLTAGE);
} catch (JSONException e) {
e.printStackTrace();
}
return session;
}
//this method will execute when we pic an item from the spinner
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//Setting the values to textviews for a selected item
}
//When no item is selected this method would execute
#Override
public void onNothingSelected(AdapterView<?> parent) {
textViewName.setText("");
textViewCourse.setText("");
textViewSession.setText("");
}
private void getdata() {
StringRequest stringRequest = new StringRequest("http://192.168.0.108/Smart/getdata.php",
new Response.Listener<String>() {
#Override
public void onResponse(String response) {
JSONObject j = null;
try {
j = new JSONObject(response);
data = j.getJSONArray(JSON_ARRAY);
empdetails(data);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
private void empdetails(JSONArray j) {
for (int i = 0; i < j.length(); i++) {
try {
JSONObject json = j.getJSONObject(i);
names.add(json.getString(EmployeeNamearray));
} catch (JSONException e) {
e.printStackTrace();
}
}
// arrayList.add(0,"Select Employee");
spinner.setAdapter(new ArrayAdapter<String>(DashboardActivity.this, android.R.layout.simple_spinner_dropdown_item,names));
spinner.setAdapter(new ArrayAdapter<String>(DashboardActivity.this, android.R.layout.simple_spinner_dropdown_item, students));
}
//Method to get student name of a particular position+
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
Intent i = new Intent(getApplicationContext(), MainActivity.class);
startActivity(i);
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camera) {
Intent i = new Intent(getApplicationContext(), AddPlugActivity.class);
startActivity(i);
// Handle the camera action
} else if (id == R.id.nav_manage) {
Intent i = new Intent(getApplicationContext(), MainActivity.class);
startActivity(i);
return true;
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
In this method add like this
//this method will execute when we pic an item from the spinner
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
yourlist.get(position);
}
Let me know if it works for you .
Hi I am working on the list view, I just want to set the values in the listview. I posted the code as below.As per SimpleAdapter It just shows the name of the content .I want to display the count also.But the count does not displayed and in the app it only shows name of the textview instead of the count. Please suggest me solution for the problem.I also attached the screenshot.
import java.util.ArrayList;
import android.R.*;
import java.util.HashMap;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.ActionBar;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class Folders extends navigation_drawer_class {
static final String NEW = "new", OVERDUE = "overdue", ASSIGNED = "assigned", TRASH = "trash", SPAM = "spam", NAME = "name", COUNT = "count";
ListView folders_list;
String[] folders;
String[] filter_id = {
"2",
"3",
"4",
"5",
"6"
};
List < String > folder_count;
JSONArray quick_view_array;
JSONObject quick_view_obj, count_obj;
String new_count, overdue_count, assigned_count, trash_count, spam_count;
List < HashMap < String, String >> menuItems;
Dialog dialog;
String URL;
Operation op = new Operation();
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//setContentView(R.layout.folders);
new getbrand().execute();
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
//-----------------------
getLayoutInflater().inflate(R.layout.folders, frameLayout);
mDrawerList.setItemChecked(position, true);
setTitle(listArray[position]);
//------------------------
if (Operation.isNetworkAvailable(this)) {
folders_list = (ListView) findViewById(R.id.folder_display_list);
new folders().execute();
folders_list.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView << ? > parent, View view, int position, long id) {
// TODO Auto-generated method stub
String fid = filter_id[position];
String title = folders[position];
Intent i = new Intent(Folders.this, Tickets.class);
i.putExtra("filter_id", "&vis_filter_id=" + fid);
i.putExtra("title", title);
i.putExtra("set_queue", "no");
startActivity(i);
}
});
} else {
Operation.showToast(getApplicationContext(), R.string.no_network);
}
}
private class folders extends AsyncTask < Void, Void, JSONArray > {
Dialog dialog;
#Override
public void onPreExecute() {
dialog = new Dialog(Folders.this, android.R.style.Theme_Translucent_NoTitleBar);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.progressbar);
dialog.show();
}
#Override
protected JSONArray doInBackground(Void...params) {
// TODO Auto-generated method stub
URL = op.getUrl(getApplicationContext(), "ticket", "quick_view", "");
quick_view_array = JSONfunctions.getJSONfromURL(URL + "&vis_encode=json", Folders.this);
return quick_view_array;
}
#Override
public void onPostExecute(JSONArray quick_view_array) {
super.onPostExecute(quick_view_array);
try {
quick_view_obj = quick_view_array.getJSONObject(0);
count_obj = quick_view_obj.getJSONObject("count");
folder_count = new ArrayList < String > ();
folder_count.add(count_obj.getString(NEW));
folder_count.add(count_obj.getString(OVERDUE));
folder_count.add(count_obj.getString(ASSIGNED));
folder_count.add(count_obj.getString(TRASH));
folder_count.add(count_obj.getString(SPAM));
folders = getResources().getStringArray(R.array.folders);
menuItems = new ArrayList < HashMap < String, String >> ();
for (int i = 0; i < filter_id.length; i++) {
HashMap < String, String > map = new HashMap < String, String > ();
map.put(NAME, folders[i]);
map.put(COUNT, folder_count.get(i));
menuItems.add(map);
}
SimpleAdapter list = new SimpleAdapter(Folders.this,
menuItems,
R.layout.folders,
new String[] {
NAME,
COUNT
},
new int[] {
R.id.folder_name, R.id.folder_count
}
);
folders_list.setAdapter(list);
dialog.dismiss();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.home, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
String filter_id = null, Tickets_title = null;
int start_limit = 0, page_no = 1;
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.menu_inbox:
Intent inbox = new Intent(Folders.this, Tickets.class);
inbox.putExtra("filter_id", "&vis_filter_id=1");
inbox.putExtra("title", "Inbox");
inbox.putExtra("set_queue", "no");
startActivity(inbox);
return true;
case R.id.menu_new_ticket:
Intent new_ticket = new Intent(Folders.this, New_Ticket_step1.class);
startActivity(new_ticket);
return true;
case R.id.menu_ticket_queue:
Intent ticket_queue = new Intent(Folders.this, Queues.class);
ticket_queue.putExtra("set_queue", "set");
startActivity(ticket_queue);
return true;
case R.id.menu_clients:
Intent clients = new Intent(Folders.this, Client.class);
startActivity(clients);
return true;
/* case R.id.menu_blabby:
Intent blabby = new Intent(Folders.this,Blabby.class);
blabby.putExtra("operation","get_blabs");
blabby.putExtra("filter","");
blabby.putExtra("title",(String)getString(R.string.blabs));
startActivity(blabby);
return true; */
//-------- Added for separate page
case R.id.menu_pin:
Intent pin = new Intent(Folders.this, Pinned_items.class);
startActivity(pin);
return true;
//-------- Added for separate page
case R.id.menu_settings:
Intent settings = new Intent(Folders.this, Settings.class);
startActivity(settings);
return true;
case R.id.menu_ticket_search:
Intent search = new Intent(Folders.this, Search.class);
search.putExtra("set_queue", "no");
startActivity(search);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
#Override
public void onBackPressed() {
moveTaskToBack(true);
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
this.finish();
}
private class getbrand extends AsyncTask < Void, Void, JSONArray > {
Dialog dialog;
#Override
public void onPreExecute() {
dialog = new Dialog(Folders.this, android.R.style.Theme_Translucent_NoTitleBar);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.progressbar);
dialog.show();
}
#Override
protected JSONArray doInBackground(Void...params) {
// TODO Auto-generated method stub
String access = op.getUrl(getApplicationContext(), "ticket", "get_branding", "");
JSONArray access_denied = JSONfunctions.getJSONfromURL(access + "&vis_encode=json", Folders.this);
return access_denied;
}
#Override
public void onPostExecute(JSONArray access_denied) {
super.onPostExecute(access_denied);
String access_result = access_denied.toString();
ActionBar ab = getActionBar();
if (access_result.equals("[\"1\"]")) {
ab.setTitle(R.string.app_name);
ab.setIcon(R.drawable.application_icon);
// ab.setDisplayShowTitleEnabled(false);
// ab.setDisplayShowHomeEnabled(false);
// ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ffffff")));
} else {
ab.setTitle(R.string.nobrand_app_name);
ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ffffff")));
ab.setIcon(R.drawable.white3);
}
dialog.dismiss();
}
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="3dp"
android:weightSum="100">
<TextView
android:id="#+id/folder_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="30"
android:text="TextView"
android:textColor="#115c28"
android:textSize="15dp" />
<TextView
android:id="#+id/folder_count"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginRight="10dp"
android:layout_weight="70"
android:gravity="center"
android:text="0"
android:textColor="#115c28"
android:textSize="20dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:orientation="vertical">
<ListView
android:id="#+id/folder_display_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="3dp"
android:weightSum="100">
<TextView
android:id="#+id/folder_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
The first textview takes up the full width of the horizontal LinearLayout so you can't see the second textview.
You can see the count by making the width of the textviews wrap_content but it probably won't match the design you're trying to achieve.
Hi i just chage the xml template as follows.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:orientation="vertical"
android:weightSum="100"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<!-- -->
<TextView
android:id="#+id/folder_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="30dip"
android:textSize="15dp"
android:layout_weight="1"
android:textColor="#115c28"/>
<TextView
android:id="#+id/folder_count"
android:layout_width="0dp"
android:layout_height="60dp"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="#115c28"
android:gravity="center"
android:paddingRight="30dip"
android:paddingLeft="35dip"
android:layout_weight="1" />
<!-- -->
</LinearLayout>
<ListView
android:id="#+id/folder_display_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
Its working properly now.
I'm new to Android and Rest Template.I have developed a android
screen and display JSON data using Rest Template GET method on my
screen.My next step is to update some fields like edit name and add
missing things and save back to the rest Template.
public class MyPreferences extends AppCompatActivity {
TextView tv;
private Listcp = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_preferences);
Resources resources = getResources();
Log.d("Consumer pojo", "onCreate:");
new HttpRequestTask().execute();
}
private class HttpRequestTask extends AsyncTask<Void, Void, ConsumerProfile>{
#Override
protected ConsumerProfile doInBackground(Void... params) {
try {
final String url = "http://192.168.1.213:9001/consumer/local/"+LoginFragment.CONSUMEROBJECT.getId();
RestTemplate restTemplate = new RestTemplate();
ConsumerProfile cp = restTemplate.getForObject(url, ConsumerProfile.class);
return cp;
}catch (Exception e){
Log.e("MainActivity", e.getMessage(),e );
}
return null;
}
#Override
protected void onPostExecute(ConsumerProfile cp){
super.onPostExecute(cp);
Log.d("cppppppppppppppppppppp", "onPostExecute: " + cp.getId());
TextView fname=(TextView)findViewById(R.id.editfname);
TextView mname=(TextView)findViewById(R.id.editmname);
TextView lname=(TextView)findViewById(R.id.editlname);
TextView nname=(TextView)findViewById(R.id.editnname);
TextView dob=(TextView)findViewById(R.id.editdob);
TextView status=(TextView)findViewById(R.id.editstatus);
TextView homeAddress=(TextView)findViewById(R.id.edithomeAddr);
TextView workAddress=(TextView)findViewById(R.id.editworkAddr);
TextView income=(TextView)findViewById(R.id.editincome);
fname.setText(cp.getFirstName());
mname.setText(cp.getMiddleName());
lname.setText(cp.getLastName());
nname.setText(cp.getNickName());
dob.setText(cp.getDob());
status.setText(cp.getStatus());
homeAddress.setText(cp.getHomeAddress());
workAddress.setText(cp.getWorkAddress());
income.setText(cp.getIncome());
}
}This Screen is for Get Method
This is what I did Up to Now.
This code is for Get method.
It'll display The screen like in image.
<?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="fill_parent"
android:orientation="vertical"><![CDATA[
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
]]>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/scrollView2" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"> <TextView
android:layout_width="wrap_content"
android:scrollbars="vertical"
android:layout_height="wrap_content"
android:text="firstName"/>
<EditText
android:id="#+id/editfname"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="middleName"/>
<EditText
android:id="#+id/editmname"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="lastName"/>
<EditText
android:id="#+id/editlname"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="nickName"/>
<EditText
android:id="#+id/editnname"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dob"/>
<EditText
android:id="#+id/editdob"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="status"/>
<EditText
android:id="#+id/editstatus"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="homeAddress"/>
<EditText
android:id="#+id/edithomeAddr"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="workAddress"/>
<EditText
android:id="#+id/editworkAddr"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="income"/>
<EditText
android:id="#+id/editincome"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:scrollbars="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Update Preferences"
android:id="#+id/button"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</ScrollView>
</LinearLayout>
This is my layout.
Actually what I'm trying to do is Get User Information and Edit Information and save back to the same end point.
When the user select Update button Then it I'll Display the Updated Screen.
Any help Appreciated.
Anyone Provide code for that.
Thankful to them.
package com.nusecond.suredeal.app.suredeal.activity;
import android.content.Intent;
import android.content.res.Resources;
import android.net.http.HttpResponseCache;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.nusecond.suredeal.app.R;
import com.nusecond.suredeal.app.suredeal.pojo.Consumer;
import com.nusecond.suredeal.app.suredeal.pojo.ConsumerProfile;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
public class MyPreferences extends AppCompatActivity {
Button button;
TextView tv;
TextView fname,mname,lname,nname,dob,status,homeAddress,workAddress,income;
private String FName,MName,LName,NName,Dob,Status,HomeAddress,WorkAddress,Income;
private List<ConsumerProfile>cp = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_preferences);
Resources resources = getResources();
Log.d("Consumer pojo", "onCreate:");
new HttpRequestTask().execute();
addListenerOnButton();
}
private void addListenerOnButton() {
//final String url = "http://192.168.1.213:9001/consumer/local/"+LoginFragment.CONSUMEROBJECT.getId();
Button button=(Button)findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
FName=fname.getText().toString();
MName=mname.getText().toString();
LName=lname.getText().toString();
NName=nname.getText().toString();
Dob=dob.getText().toString();
Status=status.getText().toString();
HomeAddress=homeAddress.getText().toString();
WorkAddress=workAddress.getText().toString();
new HttpUpdateTask().execute();
// Toast.makeText(addListenerOnButton(),"UpdatedSuccessfully",Toast.LENGTH_LONG).show();
Intent intent=new Intent(MyPreferences.this,MainActivity.class);
startActivity(intent);
}
});
}
private class HttpRequestTask extends AsyncTask<Void, Void, ConsumerProfile>{
#Override
protected ConsumerProfile doInBackground(Void... params) {
try {
final String url = "http://192.168.1.213:9001/consumer/local/"+LoginFragment.CONSUMEROBJECT.getId();
RestTemplate restTemplate = new RestTemplate();
ConsumerProfile cp = restTemplate.getForObject(url, ConsumerProfile.class);
return cp;
}catch (Exception e){
Log.e("MainActivity", e.getMessage(),e );
}
return null;
}
#Override
protected void onPostExecute(ConsumerProfile cp){
super.onPostExecute(cp);
Log.d("cppppppppppppppppppppp", "onPostExecute: " + cp.getId());
fname=(TextView)findViewById(R.id.editfname);
mname=(TextView)findViewById(R.id.editmname);
lname=(TextView)findViewById(R.id.editlname);
nname=(TextView)findViewById(R.id.editnname);
dob=(TextView)findViewById(R.id.editdob);
status=(TextView)findViewById(R.id.editstatus);
homeAddress=(TextView)findViewById(R.id.edithomeAddr);
workAddress=(TextView)findViewById(R.id.editworkAddr);
income=(TextView)findViewById(R.id.editincome);
fname.setText(cp.getFirstName());
mname.setText(cp.getMiddleName());
lname.setText(cp.getLastName());
nname.setText(cp.getNickName());
dob.setText(cp.getDob());
status.setText(cp.getStatus());
homeAddress.setText(cp.getHomeAddress());
workAddress.setText(cp.getWorkAddress());
income.setText(cp.getIncome());
//FName=fname.getText().toString();
}
}
private class HttpUpdateTask extends AsyncTask<Void,Void,ConsumerProfile>{
#Override
protected ConsumerProfile doInBackground(Void... params) {
try {
final String url = "http://192.168.1.213:9001/consumer/local/" + LoginFragment.CONSUMEROBJECT.getId();
RestTemplate restTemplate = new RestTemplate();
ConsumerProfile consumerProfile = new ConsumerProfile();
// String m=FName;
consumerProfile.setFirstName(FName);
fname=(TextView)findViewById(R.id.editfname);
Log.d(" llllllllllllll", "doInBackground: " + FName);
consumerProfile.setMiddleName(MName);
consumerProfile.setLastName(LName);
consumerProfile.setNickName(NName);
consumerProfile.setDob(Dob);
consumerProfile.setStatus(Status);
consumerProfile.setHomeAddress(HomeAddress);
consumerProfile.setWorkAddress(WorkAddress);
consumerProfile.setDob(Income);
restTemplate.put(url,consumerProfile);
Log.d("ettttttttttttttt", "doInBackground: ");
return consumerProfile;
}catch (Exception e){
Log.e( "consumer", e.getMessage(),e);
}
return null;
}
}
}
I have activities
1> mainactivity
which creates SQLite table and add stores data from edittext to mysql table
2> viewdatabse activity
which retrieves data from SQLite table and displayes in listview.
the problem is The same DATA is shown multiple time.
ex.
if i write something in edittext1 the listview will show only data of edittext1 multiple time.
here is the code of mainactivity
package com.example.androiddatabase;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
EditText name,password,date,other;
Button save,show;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name=(EditText)findViewById(R.id.nametext);
password=(EditText)findViewById(R.id.password);
date=(EditText)findViewById(R.id.time);
other=(EditText)findViewById(R.id.other);
save=(Button)findViewById(R.id.button1);
show=(Button)findViewById(R.id.button2);
save.setOnClickListener(this);
show.setOnClickListener(this);
SQLiteDatabase db=null;
try{
db=openOrCreateDatabase("MyIds",MODE_PRIVATE , null);
db.execSQL("create table if not exists MyInfo(names VARCHAR(30),passwords VARCHAR(10),dates INTEGER,others VARCHAR(500))");
}
catch(Exception e){
Toast.makeText(this, e.getMessage().toString(), Toast.LENGTH_LONG).show();
}
finally{
if(db.isOpen()){
db.close();
}
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v==save)
{
String n= name.getText().toString();
String p= password.getText().toString();
String d= date.getText().toString();
String o =other.getText().toString();
SQLiteDatabase db=null;
try{
db=openOrCreateDatabase("MyIds", MODE_PRIVATE, null);
db.execSQL("insert into MyInfo(names,passwords,dates,others)values('"+n+"','"+p+"','"+d+"','"+o+"')");
}
catch(Exception e)
{
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
finally
{
if(db.isOpen())
{
db.close();
}
}
}
else if (v==show)
{
Intent i = new Intent(this, viewdatabse.class);
startActivity(i);
}
}
}
here is the another activity which represens the listview which show data from mysql
package com.example.androiddatabase;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
public class viewdatabse extends Activity{
ListView lv;
ArrayList<HashMap<String, String>> aa;
String name,password,date,other;
HashMap<String, String> hh;
String n,p,d,o;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.listdatabse);
lv=(ListView)findViewById(R.id.listView1);
aa = new ArrayList<HashMap<String,String>>();
SQLiteDatabase db=null;
try{
db=openOrCreateDatabase("MyIds",MODE_PRIVATE , null);
Cursor c = db.rawQuery("select * from MyInfo", null);
while(c.moveToNext())
{
hh= new HashMap<String, String>();
name=c.getString(c.getColumnIndex("names"));
hh.put(n, name);
password=c.getString(c.getColumnIndex("passwords"));
hh.put(p, password);
date=c.getString(c.getColumnIndex("dates"));
hh.put(d, date);
other=c.getString(c.getColumnIndex("others"));
hh.put(o, other);
aa.add(hh);
}
}
catch(Exception e){
Toast.makeText(this, e.getMessage().toString(), Toast.LENGTH_LONG).show();
}
finally{
if(db.isOpen()){
db.close();
}
}
String s[]={n,p,d,o};
int i[]={R.id.textView1,R.id.textView2,R.id.textView3,R.id.textView4};
SimpleAdapter sa = new SimpleAdapter(this, aa, R.layout.customlist, s, i);
lv.setAdapter(sa);
}
}
here is the mainactivity xml file which has 4 edittext to take user input
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/nametext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName">
<requestFocus />
</EditText>
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
<EditText
android:id="#+id/time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="time" />
<EditText
android:id="#+id/other"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="save" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="show" />
</LinearLayout>
here is xml for view database activity which has listview to show data.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
here is the xml to create custom listview which is directly used in simpleadapter
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:textSize="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView2"
android:textSize="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>