我已经从一个活动(Activity2)中获取了输入(数字),现在我想在另一个活动中显示通行证(BubbleSortActivit),但这没有显示

时间:2019-03-20 05:04:01

标签: android

这是我的Activity2.javacode,我在其中输入输入进行排序

def check_column_existence(dbHost, dbPort, dbName, dbUser, dbPassword, table_name, column_name):
    sqlQuery="""select count(*) from 
INFORMATION_SCHEMA.columns 
where table_name='{}' and column_name='{}';""".format(table_name, column_name)
    conn = pymssql.connect(host=dbHost, port=dbPort, user=dbUser, password=dbPassword, database=dbName)
    cursor = conn.cursor()
    sql = sqlQuery.encode('utf-8')
    cursor.execute(sql)
    for row in cursor:
        if row[0] == 1:
            result = True
        else:
            result = False
    print(result)
    return result

def populate_db_attribute_existence(dbHost, dbPort, dbName, dbUser, dbPassword, input_csv_file_path):
    input_csv_file_path = os.path.abspath(input_csv_file_path)
    input_csv_folder_path = os.path.dirname(input_csv_file_path)
    input_csv_file_name = os.path.basename(input_csv_file_path)
    temp1_output_file_path = "{}/temp1_{}".format(input_csv_folder_path, input_csv_file_name)
    temp2_output_file_path = "{}/temp2_{}".format(input_csv_folder_path, input_csv_file_name)

    df = pd.read_csv(input_csv_file_path)
    df['DB_Entity'] = df['DB_Entity'].str.replace(' ', '')
    df['DB_Attributes'] = df['DB_Attributes'].str.replace(' ', '')
    df2 = df[['API_Attributes', 'DB_Entity', 'DB_Attributes']]
    df2.to_csv(temp1_output_file_path, index=False, encoding='utf-8')

    with open(temp1_output_file_path,'r') as ftemp1, open(temp2_output_file_path,'w') as ftemp2:
        i = 1
        for row in ftemp1:
            if i > 1:
                row = row.strip()
                list_columns = row.split(',')
                api_attr_name = list_columns[0]
                db_entity_name = list_columns[1]
                c_name = list_columns[2]
                t_name = 'dbo.{}'.format(db_entity_name)
                result = check_column_existence(dbHost, dbPort, dbName, dbUser, dbPassword, t_name, c_name)
                ftemp2.write(','.join([api_attr_name, db_entity_name, c_name, str(result)])+'\n')
            i += 1



    del(df2)
    df2 = pd.read_csv(temp2_output_file_path, names=['API_Attributes', 'DB_Entity', 'DB_Attributes', 'DB_Attr_Exist'])
    merge_key = ['API_Attributes', 'DB_Attributes']
    merged_df = pd.merge(df, df2, on=merge_key, how='outer')
    merged_df.to_csv(input_csv_file_path, index=False, encoding='utf-8')
    os.remove(temp1_output_file_path)
    os.remove(temp2_output_file_path)
    print("Completed DB Attributes existence check: {}".format(input_csv_file_path))

此为marge排序

package com.example.jabed.algorithmsimulator;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Activity2 extends AppCompatActivity {
     private Button button,quicksort ;
     private TextView t1;
     private EditText e1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_2);
        t1 =(TextView) findViewById(R.id.textView2);
    }

    public void onclickButton(View V){
        Intent intent = new Intent(this,MainActivity.class);
        startActivity(intent);
    }

    public void onclickButton2(View V){
          try {
              EditText e1 = (EditText) findViewById(R.id.editText2);
              t1 =(TextView) findViewById(R.id.textView2);
              button = (Button) findViewById(R.id.button1);
              quicksort = (Button) findViewById(R.id.button2);
              if (V.getId() == R.id.button2) {
                  Intent intent1 = new Intent(Activity2.this, QuicksortActivity.class);
                  startActivity(intent1);
                  Toast.makeText(Activity2.this, "You have selected Quick Sort ", Toast.LENGTH_SHORT).show();
              }


> **`when i push bubblesort button it will do this in the bellow section`**



              if (V.getId() == R.id.button3) {
                  e1 = (EditText) findViewById(R.id.editText2);
                  t1 =(TextView) findViewById(R.id.textView2);
                  String text = e1.getText().toString();

                  Intent intent = new Intent(this, BubbleSortActivity.class);
                  intent.putExtra("Extra_message",text);
                  startActivity(intent);
                  Toast.makeText(Activity2.this, "You have selected Bubble Sort ", Toast.LENGTH_SHORT).show();
                  // input ase

              }

enter image description here

这是我的bubbleSortActivity.java代码

            if (V.getId() == R.id.button4) {
                  Intent intent = new Intent(this, MargeSortActivity.class);
                  startActivity(intent);
                  Toast.makeText(Activity2.this, "You have selected Marge Sort ", Toast.LENGTH_SHORT).show();
              }
          }catch (Exception e){

                  Toast.makeText(Activity2.this,"number please",Toast.LENGTH_LONG).show();


          }


    }
}

enter image description here

2 个答案:

答案 0 :(得分:0)

在您的活动1中

public void onclickButton(View V){
Intent intent = new Intent(this,Activity2.class);
i.putStringArray("Extra_message", strArr);
startActivity(intent);
}

您已在活动2中收到此字符串数组

Intent  intent = getIntent().getExtras(); 
String[] bubble = intent.getStringArray("Extra_message");

答案 1 :(得分:0)

您需要将EditText数据从Activity2传递到BubbleSortActivity

Intent i = new Intent(this, BubbleSortActivity.class);
i.putExtra("Extra_message", e1.getText().toString());      
startActivity(i);