- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,在我的应用程序中,我有两个旋转器
spinner1 类名:
Lkg
ukg
playgroup
<小时/>
spinner2:部分名称
Batch A
Batch B
现在,如果单击提交按钮,我想显示包含姓名和学号的学生表。
现在我的问题是旋转器位于第一类中,我想访问第二类中的旋转器,然后我将通过 jsonArray
传递值并以表格格式显示数据。
第一个微调表我有唯一的键作为class_id,第二个表我有唯一的键section_id和class_id作为基于这个class_id和section_id的外键我想获取学生表如果class_id和section_id存在意味着我想获取它记录一下。
参加类(class)
public class Attend extends Activity implements
OnClickListener {
private EditText fromDateEtxt;
private DatePickerDialog fromDatePickerDialog;
private SimpleDateFormat dateFormatter;
InputStream is = null;
String result = null;
String line = null;
int class_id;
//String className = "";
String sectionName = "";
String[] class_name, section_name;
Spinner classSpinner, sectionSpinner;
private Map<String, Set<String>> classSectionMap = new HashMap<String, Set<String>>();
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
}
// Spinner element
classSpinner = (Spinner) findViewById(R.id.spinner);
sectionSpinner = (Spinner) findViewById(R.id.spinner1);
Button submit = (Button) findViewById(R.id.button1);
submit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(AndroidSpinnerExampleActivity.this,
"Result : " +
"\nclassName : "+ String.valueOf(classSpinner.getSelectedItem()) +
"\nSectionName : "+ String.valueOf(sectionSpinner.getSelectedItem()),
Toast.LENGTH_SHORT).show();
Intent i = new Intent(getApplicationContext(), Attend1.class);
startActivity(i);
}
});
dateFormatter = new SimpleDateFormat("dd-MM-yyyy", Locale.US);
findViewsById();
setDateTimeField();
// Spinner click listener
// spinner.setOnItemSelectedListener(this);
// Spinner Drop down elements
final List<String> list1 = new ArrayList<String>();
final List<String> list2 = new ArrayList<String>();
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://10.0.2.2/android_connect/getuser.php");
HttpResponse response = httpclient.execute(httppost);
Log.e("Fail 1", "3");
HttpEntity entity = response.getEntity();
Log.e("Fail 1", "4");
is = entity.getContent();
Log.e("Pass 1", "connection success ");
} catch (Exception e) {
Log.e("Fail 1", e.toString());
Toast.makeText(getApplicationContext(), "Invalid IP Address",
Toast.LENGTH_LONG).show();
finish();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
} catch (Exception e) {
Log.e("Fail 2", e.toString());
}
try {
JSONArray JA = new JSONArray(result);
JSONObject json = null;
class_name = new String[JA.length()];
section_name = new String[JA.length()];
String className = "";
String sectionName = "";
Set<String> sections;
for (int i = 0; i < JA.length(); i++) {
json = JA.getJSONObject(i);
// class_name[i] = json.getString("class_name");
// section_name[i]=json.getString("section_name");
className = json.getString("class_name");
sectionName = json.getString("section_name");
//Toast.makeText(getApplicationContext(), "classname"+sectionName, Toast.LENGTH_LONG).show();
if (classSectionMap.containsKey(className)) {
sections = classSectionMap.get(className);
} else {
sections = new HashSet<String>();
//Toast.makeText(getApplicationContext(), "classname"+className, Toast.LENGTH_LONG).show();
}
sections.add(sectionName);
classSectionMap.put(className, sections);
}
Set<String> classKeys = classSectionMap.keySet();
class_name = classKeys.toArray(new String[classKeys.size()]);
Set<String> sectionkeys = classSectionMap.get(class_name[0]);
if (sectionkeys != null) {
section_name = sectionkeys.toArray(new String[sectionkeys
.size()]);
}
/*
* for(int i=0;i<class_name.length;i++) { list1.add(class_name[i]);
* list2.add(section_name[i]);
*
* }
*/
spinner_fn();
} catch (Exception e) {
Log.e("Fail 3", e.toString());
e.printStackTrace();
// login.this.finish();
}
}
private void spinner_fn() {
// TODO Auto-generated method stub
ArrayAdapter<String> dataAdapter1 = new ArrayAdapter<String>(
getApplicationContext(), android.R.layout.simple_spinner_item,
class_name);
dataAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
classSpinner.setAdapter(dataAdapter1);
classSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int position, long id) {
Log.e("Position new", class_name[position]);
Set<String> sectionkeys = classSectionMap
.get(class_name[position]);
if (sectionkeys != null) {
section_name = sectionkeys.toArray(new String[sectionkeys
.size()]);
//Toast.makeText(getApplicationContext(), "sectionName"+section_name, Toast.LENGTH_LONG).show();
}
ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(
getApplicationContext(), android.R.layout.simple_spinner_item,
section_name);
dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sectionSpinner.setAdapter(dataAdapter2);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
sectionSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub
// spinner.setSelection(position);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
private void findViewsById() {
fromDateEtxt = (EditText) findViewById(R.id.etxt_fromdate);
fromDateEtxt.setInputType(InputType.TYPE_NULL);
fromDateEtxt.requestFocus();
// toDateEtxt = (EditText) findViewById(R.id.etxt_todate);
// toDateEtxt.setInputType(InputType.TYPE_NULL);
}
private void setDateTimeField() {
fromDateEtxt.setOnClickListener(this);
// toDateEtxt.setOnClickListener(this);
Calendar newCalendar = Calendar.getInstance();
fromDatePickerDialog = new DatePickerDialog(this,
new OnDateSetListener() {
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
Calendar newDate = Calendar.getInstance();
newDate.set(year, monthOfYear, dayOfMonth);
fromDateEtxt.setText(dateFormatter.format(newDate
.getTime()));
}
}, newCalendar.get(Calendar.YEAR),
newCalendar.get(Calendar.MONTH),
newCalendar.get(Calendar.DAY_OF_MONTH));
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
@Override
public void onClick(View view) {
if (view == fromDateEtxt) {
fromDatePickerDialog.show();
}
}
参加1.class
public class Attend1 extends Activity {
String data = "";
TableLayout tl;
TableRow tr;
TextView label;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tl = (TableLayout) findViewById(R.id.maintable);
final DataseData getdb = new DataseData();
new Thread(new Runnable() {
public void run() {
data = getdb.getDataFromDB();
System.out.println(data);
runOnUiThread(new Runnable() {
@Override
public void run() {
ArrayList<Users> users = parseJSON(data);
addData(users);
}
});
}
}).start();
}
public ArrayList<Users> parseJSON(String result) {
ArrayList<Users> users = new ArrayList<Users>();
try {
JSONArray jArray = new JSONArray(result);
for (int i = 0; i < jArray.length(); i++) {
JSONObject json_data = jArray.getJSONObject(i);
Users user = new Users();
user.setId(json_data.getInt("class_name"));
user.setClass_id(json_data.getInt("section_name"));
user.setSection_id(json_data.getInt("section_id"));
user.setName(json_data.getString("student_name"));
user.setPassword(json_data.getString("rollno"));
users.add(user);
}
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
return users;
}
void addHeader(){
tr = new TableRow(this);
label = new TextView(this);
label.setText("StudentName");
label.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
label.setPadding(5, 5, 5, 5);
label.setBackgroundColor(Color.RED);
LinearLayout Ll = new LinearLayout(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(5, 5, 5, 5);
Ll.addView(label,params);
tr.addView((View)Ll);
TextView password = new TextView(this);
password.setText("RollNo");
password.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
password.setPadding(5, 5, 5, 5);
password.setBackgroundColor(Color.RED);
Ll = new LinearLayout(this);
params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(0, 5, 5, 5);
Ll.addView(password,params);
tr.addView((View)Ll);
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
@SuppressWarnings({ "rawtypes" })
public void addData(ArrayList<Users> users) {
addHeader();
for (Iterator i = users.iterator(); i.hasNext();) {
Users p = (Users) i.next();
/** Create a TableRow dynamically **/
tr = new TableRow(this);
/** Creating a TextView to add to the row **/
label = new TextView(this);
label.setText(p.getName());
label.setId(p.getId());
label.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
label.setPadding(5, 5, 5, 5);
LinearLayout Ll = new LinearLayout(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(5, 2, 2, 2);
Ll.addView(label,params);
tr.addView((View)Ll);
TextView password = new TextView(this);
password.setText(p.getPassword());
password.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
password.setPadding(5, 5, 5, 5);
Ll = new LinearLayout(this);
params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
params.setMargins(0, 3, 3, 3);
Ll.addView(password,params);
tr.addView((View)Ll);
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
}
DataseData.class
public class DataseData {
HttpPost httppost;
HttpResponse response;
HttpClient httpclient;
List<NameValuePair> nameValuePairs;
Spinner classSpinner, sectionSpinner;
public String getDataFromDB() {
try {
HttpPost httppost;
HttpClient httpclient;
httpclient = new DefaultHttpClient();
httppost = new HttpPost(
"http://10.0.2.2/android_connect/save.php");
nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username",(String) classSpinner.getAdapter().getItem(classSpinner.getSelectedItemPosition()))); // $Edittext_value = $_POST['Edittext_value'];
nameValuePairs.add(new BasicNameValuePair("password",(String) sectionSpinner.getAdapter().getItem(sectionSpinner.getSelectedItemPosition())));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response=httpclient.execute(httppost);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
final String response = httpclient.execute(httppost,
responseHandler);
return response.trim();
} catch (Exception e) {
System.out.println("ERROR : " + e.getMessage());
return "error";
}
}
保存.php
<?php
mysql_connect("localhost","root","");
mysql_select_db("login");
$q=mysql_query("SELECT * from student");
while($row=mysql_fetch_assoc($q))
$json_output[]=$row;
print(json_encode($json_output));
mysql_close();
?>
最佳答案
试试这个。
发送值到下一个 Activity (最好作为 Activity 调用)
submit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// here AndroidSpinnerExampleActivity.this has to be replaced with Attend.this
Toast.makeText(AndroidSpinnerExampleActivity.this,
"Result : " +
"\nclassName : "+ String.valueOf(classSpinner.getSelectedItem()) +
"\nSectionName : "+ String.valueOf(sectionSpinner.getSelectedItem()),
Toast.LENGTH_SHORT).show();
Intent i = new Intent(getApplicationContext(), Attend1.class);
// here your sending the values to next class (better call as activity)
i.putExtra("class_name",classSpinner.getSelectedItem());
i.putExtra("section_name",sectionSpinner.getSelectedItem());
startActivity(i);
}
});
接收 Activity
public class Attend1 extends Activity {
String data = "";
TableLayout tl;
TableRow tr;
TextView label;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tl = (TableLayout) findViewById(R.id.maintable);
Toast.makeText(this,
"Result : " +
"\nclassName : "+ getIntent().getStringExtra("class_name") +
"\nSectionName : "+ getIntent().getStringExtra("section_name") ,
Toast.LENGTH_SHORT).show();
final DataseData getdb = new DataseData();
new Thread(new Runnable() {
public void run() {
data = getdb.getDataFromDB();
System.out.println(data);
runOnUiThread(new Runnable() {
@Override
public void run() {
ArrayList<Users> users = parseJSON(data);
addData(users);
}
});
}
}).start();
}
关于php - 如何通过android以表格格式显示访问另一个类中的微调器选定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25931406/
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 4 年前。 Improv
PowerShell Web Access 允许您通过 Web 浏览器运行 PowerShell cmdlet。它显示了一个基于 Web 的控制台窗口。 有没有办法运行 cmdlet 而无需在控制台窗
我尝试在无需用户登录的情况下访问 Sharepoint 文件。 我可以通过以下任一方式获取访问 token 方法一: var client = new RestClient("https://logi
我目前正在尝试通过 Chrome 扩展程序访问 Google 服务。我的理解是,对于 JS 应用程序,Google 首选的身份验证机制是 OAuth。我的应用目前已成功通过 OAuth 向服务进行身份
假设我有纯抽象类 IHandler 和派生自它的类: class IHandler { public: virtual int process_input(char input) = 0; };
我有一个带有 ThymeLeaf 和 Dojo 的 Spring 应用程序,这给我带来了问题。当我从我的 HTML 文件中引用 CSS 文件时,它们在 Firebug 中显示为中止。但是,当我通过在地
这个问题已经有答案了: JavaScript property access: dot notation vs. brackets? (17 个回答) 已关闭 6 年前。 为什么这不起作用? func
我想将所有流量重定向到 https,只有 robot.txt 应该可以通过 http 访问。 是否可以为 robot.txt 文件创建异常(exception)? 我的 .htaccess 文件: R
我遇到了 LinkedIn OAuth2: "Unable to verify access token" 中描述的相同问题;但是,那里描述的解决方案并不能解决我的问题。 我能够成功请求访问 toke
问题 我有一个暴露给 *:8080 的 Docker 服务容器. 我无法通过 localhost:8080 访问容器. Chrome /curl无限期挂断。 但是如果我使用任何其他本地IP,我就可以访
我正在使用 Google 的 Oauth 2.0 来获取用户的 access_token,但我不知道如何将它与 imaplib 一起使用来访问收件箱。 最佳答案 下面是带有 oauth 2.0 的 I
我正在做 docker 入门指南:https://docs.docker.com/get-started/part3/#recap-and-cheat-sheet-optional docker-co
我正在尝试使用静态 IP 在 AKS 上创建一个 Web 应用程序,自然找到了一个带有 Nginx ingress controller in Azure's documentation 的解决方案。
这是我在名为 foo.js 的文件中的代码。 console.log('module.exports:', module.exports) console.log('module.id:', modu
我试图理解访问键。我读过https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-se
我正在使用 MGTwitterEngine"将 twitter 集成到我的应用程序中。它在 iOS 4.2 上运行良好。当我尝试从任何 iOS 5 设备访问 twitter 时,我遇到了身份验证 to
我试图理解访问键。我读过https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-se
我正在使用以下 API 列出我的 Facebook 好友。 https://graph.facebook.com/me/friends?access_token= ??? 我想知道访问 token 过
401 Unauthorized - Show headers - { "error": { "errors": [ { "domain": "global", "reas
我已经将我的 django 应用程序部署到 heroku 并使用 Amazon s3 存储桶存储静态文件,我发现从 s3 存储桶到 heroku 获取数据没有问题。但是,当我测试查看内容存储位置时,除
我是一名优秀的程序员,十分优秀!