我有一个带有按钮的应用程序,也有一个textview(数字,例如100)
我是点击按钮,然后将Textview
(值)增加5。
我正在尝试将该值发送到Php表行,并且也在同一文本视图中检索表行数据。
在应用程序中已关闭并打开,然后根据Texview获取PHP数据(服务器)
my_table
MyActivity.java
public class MainActivity extends AppCompatActivity {
int minteger = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void increaseInteger(View view) {
minteger = minteger + 5 ;
display(minteger);
}
private void display(int number) {
TextView displayInteger = (TextView) findViewById(
R.id.integer_number);
displayInteger.setText("Integer: " + number);
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click the plus button to increase integer number" />
<TextView
android:id="@+id/integer_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:textSize="30sp"
android:text="Integer: 0" />
<Button
android:id="@+id/increase"
android:onClick="increaseInteger"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="INCREASE" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="bottom"
android:textSize="20sp"
android:text="viralandroid.com"/>
</LinearLayout>
答案 0 :(得分:0)
首先在private: System::Void btnOpenImage_Click(System::Object^ sender, System::EventArgs^ e)
{
//Stream;
IO::Stream^ myStream;
OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
openFileDialog1->InitialDirectory = Directory::GetCurrentDirectory();
openFileDialog1->Filter = "Image Files (JPEG,GIF,BMP,PNG,ICO)|*.jpg;*.jpeg;*.gif;*.bmp;*.png;*ico";
openFileDialog1->FilterIndex = 2;
openFileDialog1->RestoreDirectory = true;
if ( openFileDialog1->ShowDialog() ==System::Windows::Forms::DialogResult::OK)
{
file_path_temp = "image_0003.jpg";
txtImgUrl->Text = file_path_temp;
IntPtr pointer_temp = Marshal::StringToHGlobalAnsi(file_path_temp);
const char* input_location = static_cast<const char*>(pointer_temp.ToPointer());
cv::Mat imgOriginalScene = cv::imread(input_location, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
Marshal::FreeHGlobal(pointer_temp);
}
}
内初始化TextView
和您的Button
,然后从onCreate
方法中删除初始化。
display
跟随Android Button Onclick处理Android @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
displayInteger = (TextView) findViewById(
R.id.integer_number);
Button myButton = (Button) findViewById(
R.id.yourButtonId);
// Here you'll need onClickListener for the button to handle if button clicked, increase the number and etc or calling methods.
}
单击。
但是,要点是,如果将Button
添加到Button,则可以调用display或只调用onClickListener
内的setText
,而无需其他方法。(简化)
还添加:
onClickListener
在TextView displayInteger;
的上方,可以访问onCreate
和当前课程的整个范围。
要将字符串发送到服务器端,请点击以下链接:How send data to website by using android app
您首先需要通过Activity
获取文本,然后以字符串形式发送到服务器:How to get EditText value and display it on screen through TextView?