我做了一个像whatsup这样的消息传递项目。首先,我做了这个项目,它工作正常。首先你会看到contactlist。当你选择pickone时,你会看到你的对话。这是截图 的 Contactlist
讯息
这没关系。我有另一个项目,我想在其中导入消息模块。我创建另一个tabhost名称是messajlaşma。当我点击我可以看到联系人列表。 ContactlistwithTabhost 但是,当我选择选择一个ı无法在同一个tabhost中看到消息传递屏幕。我看到联系人列表和edittext混合也屏幕被锁定。我不知道为什么?
当我点击键盘
时这是我的代码:
Messages.java
public class Messages extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.messages);
bubbleLayout=(LinearLayout)findViewById(R.id.layoutbubble);
replyText=(EditText)findViewById(R.id.replytext);
sendReply=(Button)findViewById(R.id.sendbutton);
Bundle extras = getIntent().getExtras();
targetmid = extras.getInt("mid");
targetname = extras.getString("name");
targetsurname = extras.getString("surname");
targetusername = extras.getString("username");
messagetitle=(TextView)findViewById(R.id.messagetitle);
messagetitle.setText(targetname+" "+targetsurname);
imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(replyText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
try {
messagexml=getMessageWS(mid);
} catch (Exception e2) {
e2.printStackTrace();
}
Log.i("return xml", "xml is:" + messagexml);
if (!messagexml.equals("<messagelist></messagelist>")) {
// . Parse Returned XML
parseXMLWS(messagexml);
Log.i("Messages", "Messages from Webservice");
// . DB Order Insert
for (int i = 0; i < msgid.length; i++) {
messagedbInstance.insertMessages(msgid[i],msgdesc[i],date[i],createdby[i],msgto[i]);
}
}
try {
getReplydbXML=getReplyWS(mid);
} catch (Exception e2) {
e2.printStackTrace();
}
Log.i("return xml", "xml is:" + getReplydbXML);
if (!getReplydbXML.equals("<replylist></replylist>")) {
// . Parse Returned XML
parserReplyXMLWS(getReplydbXML);
Log.i("Replies", "Replies from Webservice");
// . DB Order Insert
for (int i = 0; i < rid.length; i++) {
replydbInstance.insertReplies(rid[i], msgid[i], replydesc[i], replydate[i], repliedfrom[i], repliedto[i]);
}
}
//if doesnt exist any messages from the WS Create message and reply it.
else if(messagexml.equals("<messagelist></messagelist>")){
}
// Tüm mesaj ve reply içerikleri burada gelecek
try {
getMessagedbXML = messagedbInstance.getMessages(mid,targetmid);
parseXML(getMessagedbXML);
} catch (Exception e2) {
e2.printStackTrace();
}
for( i=0;i<msgid.length;i++){
if(createdby[i]==mid){
RelativeLayout layout=new RelativeLayout(Messages.this);
LayoutParams lparams = new LayoutParams(
1200,LayoutParams.WRAP_CONTENT);
layout.setLayoutParams(lparams);
//layout.setBackgroundResource(R.drawable.bubble);
// Creating a new TextView
TextView tv = new TextView(Messages.this);
tv.setText(msgdesc[i]);
layout.setGravity(Gravity.LEFT);
tv.setPadding(30, 10, 0, 0);
layout.addView(tv);
bubbleLayout.addView(layout);
}
else if(createdby[i]==targetmid){
RelativeLayout layout=new RelativeLayout(Messages.this);
LayoutParams lparams = new LayoutParams(
1200,LayoutParams.WRAP_CONTENT);
layout.setLayoutParams(lparams);
//layout.setBackgroundResource(R.drawable.bubble);
// Creating a new TextView
TextView tv = new TextView(Messages.this);
tv.setText(msgdesc[i]);
layout.setGravity(Gravity.RIGHT);
tv.setPadding(30, 10, 0, 0);
layout.addView(tv);
bubbleLayout.addView(layout);
}
}
for( i=0;i<msgid.length;i++){
if (type[i]==0)
{
isReadMessage(msgid[i]);
}
else if (type[i]==1)
{
isReadReply(id[i]);
}
}
if(msgid.length > 0){
sendReply.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
MessageProgressBar message=new MessageProgressBar();
message.execute();
}
});
}
else {
sendReply.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(iscreatemessage==0){
ProgressBar progress=new ProgressBar();
progress.execute();
}
else{
ProgressBar2 progress=new ProgressBar2();
progress.execute();
}
}
});
}
}
ContactList.java
public class ContactList extends Activity{
public void onCreate(Bundle bundle){
super.onCreate(bundle);
setContentView(R.layout.userlist);
ContactListDB dbInstance = new ContactListDB(this);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
if (isOnline()) {
// . Get Orders From WS
try {
getResult = getUserWS();
} catch (Exception e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
Log.i("return xml", "xml is:" + getResult);
// . Get Orders From WS
//
if (!getResult.equals("<listusers></listusers>")) {
// . Parse Returned XML
parseXML(getResult);
Log.i("ContactLists", "ContactLists from Webservice");
// . Parse Returned XML
// . DB Order Insert
for (int i = 0; i < midArr.length; i++) {
dbInstance.insertMerch(midArr[i], nameArr[i], surnameArr[i],usernameArr[i]);
}
UserList=new String[midArr.length];
for (int i = 0; i < midArr.length; i++) {
//getting desc from db
getMessagedbXML = messagedbInstance.getMessages(mid,midArr[i]);
parseXMLDB(getMessagedbXML);
if(msgdesc.length == 0) {
UserList[i] = nameArr[i]+" "+surnameArr[i];
}
else{
UserList[i] = nameArr[i]+" "+surnameArr[i]+" "+msgdesc[msgdesc.length-1];
}
}
}
getDBxml = dbInstance.getMerch();
parseXML(getDBxml);
}
contactList = (ListView) findViewById(R.id.contactlist);
ArrayList<HashMap<String,String>> listItem = new ArrayList<HashMap<String,String>>();
HashMap<String,String> map;
for (int i = 0; i < midArr.length; i++) {
//getting desc from db
getMessagedbXML = messagedbInstance.getMessages(mid,midArr[i]);
parseXMLDB(getMessagedbXML);
map = new HashMap<String, String>();
if(msgdesc.length == 0){
map.put("username",nameArr[i]+" "+surnameArr[i]);
}else{
map.put("username",nameArr[i]+" "+surnameArr[i]);
map.put("message", msgdesc[msgdesc.length-1]);
}
listItem.add(map);
}
SimpleAdapter myAdapter = new SimpleAdapter(this, listItem, R.layout.contactliststyle, new String[] {"username","message"},
new int[] {R.id.username, R.id.message});
contactList.setAdapter(myAdapter);
contactList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position,
long id) {
/* Intent message = new Intent(v.getContext(), Messages.class);
message.putExtra("mid", midArr[position]);
message.putExtra("name", nameArr[position]);
message.putExtra("surname", surnameArr[position]);
message.putExtra("username", usernameArr[position]);
startActivity(message);*/
Intent message = new Intent(v.getContext(), Messages.class);
message.putExtra("mid", midArr[position]);
message.putExtra("name", nameArr[position]);
message.putExtra("surname", surnameArr[position]);
message.putExtra("username", usernameArr[position]);
startActivity(message);
}
});
}
/*
setListAdapter(new ArrayAdapter<String>(ContactList.this,R.layout.userlist,UserList));
ListView userlist=getListView();
userlist.setTextFilterEnabled(true);
userlist.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
if (!isOnline()) {
AlertDialog alertDialog = new AlertDialog.Builder(ContactList.this).create();
alertDialog.setTitle("Internet Bağlantısı");
alertDialog.setMessage("Internet bağlantınız yok.Lütfen kontrol edin.");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
} });
alertDialog.show();
}
Toast.makeText(getApplicationContext(),
(usernameArr[position]), Toast.LENGTH_SHORT).show();
Intent message = new Intent(view.getContext(), Messages.class);
message.putExtra("mid", midArr[position]);
message.putExtra("name", nameArr[position]);
message.putExtra("surname", surnameArr[position]);
message.putExtra("username", usernameArr[position]);
startActivity(message);
}
});*/
// Check Connectivity
public boolean isOnline() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
}
messages.xml
<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="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="1300dip"
android:layout_height="80dip"
android:background="#084B8A" >
<TextView
android:id="@+id/messagetitle"
android:layout_width="wrap_content"
android:layout_height="90dip"
android:layout_centerInParent="true"
android:layout_marginTop="30dip"
android:textColor="#ffffff"
android:textSize="12pt" />
</RelativeLayout>
<ScrollView
android:id="@+id/scrollLayout"
android:layout_width="1300dip"
android:layout_height="510dip" >
<LinearLayout
android:id="@+id/layoutbubble"
android:layout_width="1300dip"
android:layout_height="510dip"
android:layout_marginTop="10dip"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="1300dip"
android:layout_height="80dip"
android:layout_marginTop="10dip" >
<EditText
android:id="@+id/replytext"
android:layout_width="1000dip"
android:layout_height="90dip"
android:layout_marginLeft="10dip" />
<Button
android:id="@+id/sendbutton"
android:layout_width="200dip"
android:layout_height="90dip"
android:layout_marginLeft="1050dp"
android:background="#084B8A"
android:text="Send"
android:textColor="#ffffff"
android:textSize="12pt" />
</RelativeLayout>
userlist.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="1500dip"
android:layout_height="58px"
android:layout_gravity="fill_horizontal"
android:background="#084B8A"
android:orientation="horizontal" >
</RelativeLayout>
<ListView
android:id="@+id/contactlist"
android:layout_width="match_parent"
android:layout_height="580dip"
android:layout_marginTop="5dp"
android:cacheColorHint="#00000000"
android:dividerHeight="1dp"
android:textSize="8dp" >
</ListView>
AndroidManifest
<activity
android:name=".Messages"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:windowSoftInputMode="adjustPan" >
</activity>
<activity
android:name=".ContactList"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.Translucent.NoTitleBar" >
</activity>
Tabhosts
`package com.telpa.mobilemerch;
import android.app.TabActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
import android.content.Intent;
import android.graphics.Color;
public class MainScreen extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//For hide keyboard default
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
TabHost tabHost = getTabHost();
// Tab for Routes
TabSpec routes = tabHost.newTabSpec("Routes");
// setting Title and Icon for the Tab
routes.setIndicator("", getResources().getDrawable(R.drawable.routealt_icon));
Intent routesIntent = new Intent(this, Routes.class);
routes.setContent(routesIntent);
TabSpec panels = tabHost.newTabSpec("SahaPanel");
// setting Title and Icon for the Tab
panels.setIndicator("SahaPanel", getResources().getDrawable(R.drawable.routealt_icon));
Intent panelsIntent = new Intent(this, Panel.class);
panels.setContent(panelsIntent);
TabSpec message = tabHost.newTabSpec("Mesajlaşma");
// setting Title and Icon for the Tab
message.setIndicator("Mesajlaşma", getResources().getDrawable(R.drawable.routealt_icon));
Intent messageIntent = new Intent(this, ContactList.class);
message.setContent(messageIntent);
// Tab for orders
TabSpec orders = tabHost.newTabSpec("Orders");
orders.setIndicator("", getResources().getDrawable(R.drawable.order_icon));
Intent ordersIntent = new Intent(this, Orders.class);
orders.setContent(ordersIntent);
// Tab for Updates
TabSpec updates = tabHost.newTabSpec("Settings");
updates.setIndicator("", getResources().getDrawable(R.drawable.setting_icon));
Intent updatesintent = new Intent(this, Settings.class);
updates.setContent(updatesintent);
// Adding all TabSpec to TabHost
tabHost.addTab(routes); // Adding routes
tabHost.addTab(panels);//Adding Panel
tabHost.addTab(message);//Adding Panel
tabHost.addTab(orders); // Adding orders
tabHost.addTab(updates); // Adding updates
tabHost.setCurrentTab(0);
}
}`