Reputation: 1
Hi Im making the finishing touches on my first app have hit a roadblock Im trying to call the results of my
textview1.getText(k);
down below to the public boolean onOptionsItemSelected(MenuItem item,View v)
where an intent allows the user to send it as an text message but for some odd reason its not reading (k) my guess is it can't find the variable(k) for some odd reason. full code is down below any help is welcomed.
P.S Sorry my code is sloppy still a little new to programming.
package com.Converter;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;
public class Converter extends Activity {
Button b1 ;
EditText edittext;
RadioButton rad1, rad2;
TextView textview1 ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edittext = (EditText) findViewById(R.id.edittext);
rad1 = (RadioButton) findViewById(R.id.rad1);
rad2 = (RadioButton) findViewById(R.id.rad2);
textview1 = (TextView) findViewById(R.id.textview1);
}
public void onClick(View v)
{
if(rad1.isChecked())
{
String s1 = edittext.getText().toString();
byte[] bytes = s1.getBytes();
StringBuilder k= new StringBuilder();
for (byte b : bytes)
{
int val = b - '0';
for (int i = 0; i < 8; i++)
{
k.append((val & 128) == 0 ? 0 : 1);
val <<= 1;
}
k.append(' ');
}
textview1.setText(k);
}
if(rad2.isChecked())
{
int charCode;
String k = "";
String b = edittext.getText().toString();;
while (b.length() > 8) {
charCode = Integer.parseInt(b.substring(0, 8),2);
k += new Character((char)charCode).toString();
b = b.substring(8);
}
if (b.length() > 0) {
//attempt handle any trailing bits that might be left
charCode = Integer.parseInt(b,2);
k += new Character((char)charCode).toString();
}
textview1.setText(k);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item,View v) {
String smsbody = textview1.getText(k);
switch (item.getItemId()) {
case R.id.icon: Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", smsbody);
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
break;
case R.id.text: Toast.makeText(this, "Testing!", Toast.LENGTH_LONG).show();
break;
case R.id.icontext: Toast.makeText(this, "Testing", Toast.LENGTH_LONG).show();
break;
}
return true;
}
}
Upvotes: 0
Views: 596
Reputation: 4811
If you are refering to
String smsbody = textview1.setText(k);
it needs to be changed to
String smsbody = textview1.getText(k);
as you are reading the text, not setting it.
Edit
Button btn = (Button)findViewById(R.id.button);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Do your logic here
}
});
Here's a basic onClick interface model
Upvotes: 1
Reputation: 46844
Do you mean String smsbody = textview1.getText();
Note the *g*et, not *s*et.
Upvotes: 0