• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps need help with coding

creativeT

Lurker
Oct 23, 2016
5
0
hi guys

first i would like to say i am a complete newbie in android studio but i am willing to develop my self

in my course i ran into a problem

i have an interface for my android app i am currently working on

interface layout have

update button

textveiw 1
textveiw 2
textveiw 3
textveiw 4

database
1 table containing 1 row with 4 columns every column contains flout value

i created the connect.php + show.php files and they working find

show.php have a sql query select the 4 columns

show display array of the result

idea is user user will press on the update button
then the button will take the flout values of columns like this

textveiw 1>>>>display the value of the 1st columns
textveiw 2>>>>display the value of the 2nd columns
textveiw 3>>>>display the value of the 3rd columns
textveiw 4>>>>display the value of the 4th columns

problem is i do not know what kind of code i have to write in the update button to make this scenario works fine

and sorry i am still a starter in this programming language

please help me

i would be grateful
 
In terms of writing a Button onClick listener, there's an example here

https://developer.android.com/reference/android/widget/Button.html

To help you with the actual code for the onClick method, we'd need to know more information about your app, such as:

- Your UI layout design. What are your TextViews called?
- How you're obtaining the data from your database

As it stands, there is really not enough information to suggest anything useful that could answer your question.
 
Upvote 0
first

dbconnect.php as follow :

<?php
define('host','localhost');
define('user','root');
define('pass','tiger');
define('db','ourdb');

$con= mysqli_connect(host,user,pass,db) or die('Unable to Connect');
?>

show data.php
<?php
include("dbconnect.php");
header('content-type: text/html;');
{
$sql = "SELECT american_dollar,saudi_rial,emarati_dirham,omani_rial FROM buying_rates WHERE id = 2";

$result = mysqli_query($con,$sql);

$row = mysqli_fetch_array($result);

$currency = array();

array_push($currency,array(
"american"=>$row['american_dollar'],
"saudi"=>$row['saudi_rial'],
"emarati"=>$row['emarati_dirham'],
"omani"=>$row['omani_rial']
)
);

echo json_encode(array("result"=>$currency));


mysqli_close($con);
}

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.hamoodi.myapp.MainActivity">

<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="61dp"
android:layout_marginStart="61dp"
android:layout_marginTop="84dp"
android:id="@+id/textView"
android:textSize="24sp" />

<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_alignLeft="@+id/textView"
android:layout_alignStart="@+id/textView"
android:layout_marginTop="63dp"
android:id="@+id/textView2"
android:textSize="24sp" />

<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView3"
android:layout_alignRight="@+id/textView3"
android:layout_alignEnd="@+id/textView3"
android:layout_marginRight="11dp"
android:layout_marginEnd="11dp"
android:layout_marginTop="69dp"
android:id="@+id/textView4"
android:textSize="24sp" />

<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="66dp"
android:id="@+id/textView3"
android:layout_below="@+id/textView2"
android:layout_alignLeft="@+id/textView2"
android:layout_alignStart="@+id/textView2"
android:textSize="24sp" />

<Button
android:text="Update"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="25dp"
android:layout_marginEnd="25dp"
android:layout_marginTop="27dp"
android:id="@+id/button"
android:textSize="24sp" />
</RelativeLayout>

mainactivity.java

package com.example.hamoodi.myapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

i hope i provided all info needed

thanks in advance
 
Upvote 0
Ok thank you for the code, but here's your next starter for ten..

How (and where) is your PHP code being run, and how does the data it extracts from the database get into your Android app?

Let's put it this way - if you don't already have some code which obtains the data, then that is your number one problem to solve, before you get to issues about how to display the data.
 
Upvote 0
my php run from my pc localhost apache server

but for the how? thats what i am looking for

your question is what i wanted actually

how does the data it extracts from the database get into your Android app?

this is what i am looking for i want to know how to put the data into the android app using that the update button in the layout design
 
Upvote 0
So in the above link

http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/

You want to focus on section 7, which does pretty much exactly what you are trying to do i.e. a couple of buttons, which when clicked, call a remote web service to retrieve some data. What I suggest is that you read this carefully and adapt the code which they give you. Hint: the LoadAllProducts class is the code which does the work of calling the web service.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones