I have 2 classes BlockIdActivity.java and ScanWifi.java. I have 2 buttons in BlockIdActivity.java file and i am able to see my toast defined there. However i cant see the toast for the button i defined in ScanWifi.Java class.
Following is the code for BlockIdActivity.java
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
public class BlockIdActivity extends ActionBarActivity {
private ImageButton mUpButton;
private ImageButton mDownButton;
private TextView mBlock_Id_Field;
int counter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_block_id);
mUpButton = (ImageButton)findViewById(R.id.arrow_up);
mDownButton = (ImageButton)findViewById(R.id.arrow_down);
mBlock_Id_Field = (TextView)findViewById(R.id.BlockIdField);
mUpButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mBlock_Id_Field.getText().toString().trim().equals(""))
{
counter = 1;
mBlock_Id_Field.setText(String.valueOf(counter));
}
else {
counter = Integer.valueOf(mBlock_Id_Field.getText().toString().trim());
counter++;
mBlock_Id_Field.setText(String.valueOf(counter));
}
}
});
mDownButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int counter = Integer.valueOf(mBlock_Id_Field.getText().toString().trim());
// boolean emptyfield = mBlock_Id_Field.getText().toString().equals("");
if(counter <=1 ){
Toast.makeText(BlockIdActivity.this,
R.string.negative_blockid_toast,
Toast.LENGTH_SHORT).show();
counter = 1;
mBlock_Id_Field.setText(String.valueOf(counter));
}else {
counter--;
mBlock_Id_Field.setText(String.valueOf(counter));
}
}
});
}
}
and code for ScanWifi.java
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class ScanWifi extends ActionBarActivity {
private Button mScanWifiButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_block_id);
mScanWifiButton = (Button)findViewById(R.id.ScanWifiButton);
mScanWifiButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getBaseContext(),
R.string.ScanWifi_toast,
Toast.LENGTH_SHORT).show();
}
});
}
}
This is the strings.xml file :
<resources>
<string name="app_name">SnifferTrain</string>
<string name="BlockId">BlockId</string>
<string name="ScanWifi">ScanWifi</string>
<string name="ScanWifi_toast">ScanWifi Button Pressed</string>
<string name="negative_blockid_toast">Block Id Field Cannot Be Less Than 1 or Empty.Setting BlockID To 1</string>
<string name="action_settings">Settings</string>
</resources>
Can someone please explain why ScanWifi_toast does not show when i press ScanWifi Button. I have tried changing the context of the toast to ScanWifi.this or getApplicationContext() but it doesn't seem to work. I don't get any compilation errors. Please help