- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 android 的新手,现在我在 ListView 中遇到了一些问题,一个列表屏幕在列表中有一些名字,当我点击这些名字中的任何一个时,它应该将该 id 传递给另一个 Activity 以及在哪里它必须根据代码从数据库中获取一些数据但我的 Activity 正在停止......所以请任何人帮助我......alluseractivity 连接到显示一些列表的列表,它正在工作,但 employeedetails 该 Activity 有一些问题....我也给了 xml 代码和 php 代码所以请在这里帮助我..这是 logcat View ......同一个代码中的另一个问题先生,当我尝试更新这些东西并再次从头开始运行它停止到达此屏幕之前我正在将代码添加到 empdetailsactivity 所以请检查它并让我知道
E/AndroidRuntime(803): android.os.NetworkOnMainThreadException
android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
libcore.io.IoBridge.connectErrno(IoBridge.java:127)
libcore.io.IoBridge.connect(IoBridge.java:112)
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
java.net.Socket.connect(Socket.java:842)
org.apache.http.conn.scheme.PlainSocketFactory.connectSocket
(PlainSocketFactory.java:119)
org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(
DefaultClientConnectionOperator.java:144)
org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
org.apache.http.impl.conn.AbstractPooledConnAdapter.open
(AbstractPooledConnAdapter.java:119)
org.apache.http.impl.client.DefaultRequestDirector.execute
(DefaultRequestDirector.java:360)
org.apache.http.impl.client.AbstractHttpClient.execute
(AbstractHttpClient.java:555)
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
com.example.demo3.JSONParser.makeHttpRequest(JSONParser.java:61)
com.example.demo3.EmpDetailsActivity$GetEmployeeDetails$1.run
(EmpDetailsActivity.java:95)
android.os.Handler.handleCallback(Handler.java:725)
android.os.Handler.dispatchMessage(Handler.java:92)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:5041)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
dalvik.system.NativeStart.main(Native Method)
public class AllUserActivity extends ListActivity {
private ProgressDialog pDialog;
JSONParser jParser = new JSONParser();
ArrayList<HashMap<String, String>> employeesList;
private static String url_all_emp = "http://10.0.2.2/get_all_employees.php";
private static final String TAG_SUCCESS = "success";
private static final String TAG_EMPLOYEES = "emp";
private static final String TAG_EID = "eid";
private static final String TAG_NAME = "username";
JSONArray employees = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.all_employees);
// Hashmap for ListView
employeesList = new ArrayList<HashMap<String, String>>();
new LoadAllProducts().execute();
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
String eid = ((TextView) view.findViewById(R.id.eid)).getText().toString();
Intent in = new Intent(getApplicationContext(),EmpDetailsActivity.class);
in.putExtra(TAG_EID, eid);
startActivityForResult(in, 100);
}
});}
class LoadAllProducts extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(AllUserActivity.this);
pDialog.setMessage("Loading employees. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(url_all_emp, "GET", params);
Log.d("All Employees: ", json.toString());
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
employees = json.getJSONArray(TAG_EMPLOYEES);
for (int i = 0; i < employees.length(); i++) {
JSONObject c = employees.getJSONObject(i);
String eid = c.getString(TAG_EID);
String username = c.getString(TAG_NAME);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_EID, eid);
map.put(TAG_NAME, username);
employeesList.add(map);
}
} else {
Intent i = new Intent(getApplicationContext(),
MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
runOnUiThread(new Runnable() {
public void run() {
ListAdapter adapter = new SimpleAdapter(
AllUserActivity.this, employeesList,
R.layout.list_item, new String[] { TAG_EID,TAG_NAME},
new int[] { R.id.eid, R.id.username });
setListAdapter(adapter);
}
});
}
}
}
public class EmpDetailsActivity extends Activity
{
EditText txtName;
EditText txtfname;
EditText txtlname;
EditText txtpwd;
EditText txtloc;
EditText txtcnct;
String eid;
private ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
private static final String url_get_emp = "http://10.0.2.2/img1/get_emp_det.php";
private static final String url_update_emp = "http://10.0.2.2/img1/update_emp.php";
private static final String TAG_SUCCESS = "success";
private static final String TAG_EMPLOYEE = "emp";
private static final String TAG_EID = "eid";
private static final String TAG_NAME = "username";
private static final String TAG_FNAME = "firstname";
private static final String TAG_LNAME = "lastname";
private static final String TAG_PWD = "password";
private static final String TAG_LOC = "location";
private static final String TAG_CNCT= "contact";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_employee);
if (android.os.Build.VERSION.SDK_INT > 9){ StrictMode.ThreadPolicy policy = new
StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
Intent i = getIntent();
eid = i.getStringExtra(TAG_EID);
new GetEmployeeDetails().execute();
btnSave.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// starting background task to update employee
new SaveemployeeDetails().execute();
}
});
}
class GetEmployeeDetails extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(EmpDetailsActivity.this);
pDialog.setMessage("Loading employee details. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected String doInBackground(String... params) {
runOnUiThread(new Runnable() {
public void run() {
int success;
try {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("eid", eid));
JSONObject json = jsonParser.makeHttpRequest(
url_get_emp, "GET", params);
Log.d("Single employee Details", json.toString());
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
JSONArray employeeObj = json
.getJSONArray(TAG_EMPLOYEE);
JSONObject employee = employeeObj.getJSONObject(0);
txtName = (EditText) findViewById(R.id.inputName);
txtfname = (EditText) findViewById(R.id.inputfName);
txtcnct = (EditText) findViewById(R.id.cnct);
txtpwd = (EditText) findViewById(R.id.pwd);
txtlname= (EditText) findViewById(R.id.inputlName);
txtloc = (EditText) findViewById(R.id.loc);
txtName.setText(employee.getString(TAG_NAME));
txtfname.setText(employee.getString(TAG_FNAME));
txtlname.setText(employee.getString(TAG_LNAME));
txtpwd.setText(employee.getString(TAG_PWD));
txtjob.setText(employee.getString(TAG_JOB));
txtloc.setText(employee.getString(TAG_LOC));
txtcnct.setText(employee.getString(TAG_CNCT));
}else{
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
return null;
}
protected void onPostExecute(String file_url) {
// dismiss the dialog once got all details
pDialog.dismiss();
}
}
class SaveemployeeDetails extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(EmpDetailsActivity.this);
pDialog.setMessage("Saving employee ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected String doInBackground(String... args) {
// getting updated data from EditTexts
String name = txtName.getText().toString();
String fname = txtfname.getText().toString();
String lname = txtlname.getText().toString();
String cnct = txtcnct.getText().toString();
String pwd = txtpwd.getText().toString();
String loc = txtloc.getText().toString();
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair(TAG_EID, eid));
params.add(new BasicNameValuePair(TAG_NAME, name));
params.add(new BasicNameValuePair(TAG_FNAME, fname));
params.add(new BasicNameValuePair(TAG_LNAME, lname));
params.add(new BasicNameValuePair(TAG_PWD, pwd));
params.add(new BasicNameValuePair(TAG_CNCT, cnct));
params.add(new BasicNameValuePair(TAG_LOC, loc));
// sending modified data through http request
// Notice that update employee url accepts POST method
JSONObject json = jsonParser.makeHttpRequest(url_update_employee,
"POST", params);
// check json success tag
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully updated
Intent i = getIntent();
setResult(100, i);
finish();
} else {
// failed to update employee
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
// dismiss the dialog once employee uupdated
pDialog.dismiss();
}
}
}
<?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" >
<!-- Name Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Employee Name"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="10dip"
android:textSize="17dip"/>
<!-- Input Name -->
<EditText android:id="@+id/inputName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:layout_marginBottom="15dip"
android:singleLine="true"/>
<!-- Name Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Employee fName"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="10dip"
android:textSize="17dip"/>
<!-- Input Name -->
<EditText android:id="@+id/inputfName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:layout_marginBottom="15dip"
android:singleLine="true"/>
<!-- Name Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Employee lName"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="10dip"
android:textSize="17dip"/>
<!-- Input Name -->
<EditText android:id="@+id/inputlName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:layout_marginBottom="15dip"
android:singleLine="true"/>
<!-- Name Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Employee pwd"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="10dip"
android:textSize="17dip"/>
<!-- Input Name -->
<EditText android:id="@+id/pwd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:layout_marginBottom="15dip"
android:singleLine="true"/>
<!-- Name Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Employee cnct"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="10dip"
android:textSize="17dip"/>
<!-- Input Name -->
<EditText android:id="@+id/cnct"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:layout_marginBottom="15dip"
android:singleLine="true"/>
<!-- salary Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="loc"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="10dip"
android:textSize="17dip"/>
<!-- Input salary -->
<EditText android:id="@+id/loc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:layout_marginBottom="15dip"
android:gravity="top"/>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button android:id="@+id/btnSave"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/save_changes"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
<?php
$response = array();
require_once __DIR__ . '/db_connect.php';
$db = new DB_CONNECT();
if (isset($_GET["eid"])) {
$eid = $_GET['eid'];
$result = mysql_query("SELECT * FROM userss WHERE eid = $eid");
if (!empty($result)) {
if (mysql_num_rows($result) > 0) {
$result = mysql_fetch_array($result);
$emp = array();
$emp["eid"] = $result["eid"];
$emp["firstname"] = $result["firstname"];
$emp["lastname"] = $result["lastname"];
$emp["username"] = $result["username"];
$emp["password"] = $result["password"];
$emp["location"] = $result["location"];
$emp["contact"] = $result["contact"];
// success
$response["success"] = 1;
// user node
$response["emp"] = array();
array_push($response["emp"], $emp);
// echoing JSON response
echo json_encode($response);
} else {
// no emp found
$response["success"] = 0;
$response["message"] = "No emp found";
// echo no users JSON
echo json_encode($response);
}
} else {
// no emp found
$response["success"] = 0;
$response["message"] = "No emp found";
// echo no users JSON
echo json_encode($response);
}
} else {
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
echo json_encode($response);
}
?>
最佳答案
Put the below code just below the setContentView() in your activity.
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
If error comes after saving your application then just mouseover the error and add @SuppressLint("NewApi")(Eclipse will give you option on mouse over).For example you will get an error on the word "build".Inform me if it works.
关于php - android使用php脚本从数据库中检索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22793563/
我最近在/ drawable中添加了一些.gifs,以便可以将它们与按钮一起使用。这个工作正常(没有错误)。现在,当我重建/运行我的应用程序时,出现以下错误: Error: Gradle: Execu
Android 中有返回内部存储数据路径的方法吗? 我有 2 部 Android 智能手机(Samsung s2 和 s7 edge),我在其中安装了一个应用程序。我想使用位于这条路径中的 sqlit
这个问题在这里已经有了答案: What's the difference between "?android:" and "@android:" in an android layout xml f
我只想知道 android 开发手机、android 普通手机和 android root 手机之间的实际区别。 我们不能从实体店或除 android marketplace 以外的其他地方购买开发手
自Gradle更新以来,我正在努力使这个项目达到标准。这是一个团队项目,它使用的是android-apt插件。我已经进行了必要的语法更改(编译->实现和apt->注释处理器),但是编译器仍在告诉我存在
我是android和kotlin的新手,所以请原谅要解决的一个非常简单的问题! 我已经使用导航体系结构组件创建了一个基本应用程序,使用了底部的导航栏和三个导航选项。每个导航选项都指向一个专用片段,该片
我目前正在使用 Facebook official SDK for Android . 我现在正在使用高级示例应用程序,但我不知道如何让它获取应用程序墙/流/状态而不是登录的用户。 这可能吗?在那种情
我在下载文件时遇到问题, 我可以在模拟器中下载文件,但无法在手机上使用。我已经定义了上网和写入 SD 卡的权限。 我在服务器上有一个 doc 文件,如果用户单击下载。它下载文件。这在模拟器中工作正常但
这个问题在这里已经有了答案: What is the difference between gravity and layout_gravity in Android? (22 个答案) 关闭 9
任何人都可以告诉我什么是 android 缓存和应用程序缓存,因为当我们谈论缓存清理应用程序时,它的作用是,缓存清理概念是清理应用程序缓存还是像内存管理一样主存储、RAM、缓存是不同的并且据我所知,缓
假设应用程序 Foo 和 Eggs 在同一台 Android 设备上。任一应用程序都可以获取设备上所有应用程序的列表。一个应用程序是否有可能知道另一个应用程序是否已经运行以及运行了多长时间? 最佳答案
我有点困惑,我只看到了从 android 到 pc 或者从 android 到 pc 的例子。我需要制作一个从两部手机 (android) 连接的 android 应用程序进行视频聊天。我在想,我知道
用于使用 Android 以编程方式锁定屏幕。我从 Stackoverflow 之前关于此的问题中得到了一些好主意,并且我做得很好,但是当我运行该代码时,没有异常和错误。而且,屏幕没有锁定。请在这段代
文档说: android:layout_alignParentStart If true, makes the start edge of this view match the start edge
我不知道这两个属性和高度之间的区别。 以一个TextView为例,如果我将它的layout_width设置为wrap_content,并将它的width设置为50 dip,会发生什么情况? 最佳答案
这两个属性有什么关系?如果我有 android:noHistory="true",那么有 android:finishOnTaskLaunch="true" 有什么意义吗? 最佳答案 假设您的应用中有
我是新手,正在尝试理解以下 XML 代码: 查看 developer.android.com 上的文档,它说“starStyle”是 R.attr 中的常量, public static final
在下面的代码中,为什么当我设置时单选按钮的外观会发生变化 android:layout_width="fill_parent" 和 android:width="fill_parent" 我说的是
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 9
假设我有一个函数 fun myFunction(name:String, email:String){},当我调用这个函数时 myFunction('Ali', 'ali@test.com ') 如何
我是一名优秀的程序员,十分优秀!